Refactor build routine and switch to airbnb style (#1703)
- Relocate webpack stuff to assets/build
- Switch all js to airbnb code style
- Update webpack to v2.0 (beta)
- Update all other dependencies
- Assets manifest uses relative path as key [1]
- Code should be compatible with Node 4.5.0
- All dependencies have been updated
[1]: Previously the assets manifest would use the basename of a file path as
its key when looking up a cachebusted file. This was to be consistent with
Sage 8. This change makes it so that the relative path is used instead.
To clarify, review the following example.
Before:
```
{
"main.js": "scripts/main_5f4bfc9a9f82291c6dea.js",
"main.css": "styles/main_5f4bfc9a9f82291c6dea.css",
"customizer.js": "scripts/customizer_5f4bfc9a9f82291c6dea.js"
}
```
After:
```
{
"scripts/main.js":"scripts/main_5f4bfc9a9f82291c6dea.js",
"styles/main.css":"styles/main_5f4bfc9a9f82291c6dea.css",
"scripts/customizer.js":"scripts/customizer_5f4bfc9a9f82291c6dea.js"
}
```
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import $ from 'jquery';
|
||||
|
||||
wp.customize('blogname', (value) => {
|
||||
value.bind((to) => $('.brand').text(to))
|
||||
value.bind((to) => $('.brand').text(to));
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// import external dependencies
|
||||
import 'jquery'
|
||||
import 'bootstrap/dist/js/bootstrap'
|
||||
import 'jquery';
|
||||
import 'bootstrap/dist/js/bootstrap';
|
||||
|
||||
// import local dependencies
|
||||
import Router from './util/router';
|
||||
import common from './routes/Common';
|
||||
import home from './routes/Home';
|
||||
import about_us from './routes/About';
|
||||
import aboutUs from './routes/About';
|
||||
|
||||
// Use this variable to set up the common and page specific functions. If you
|
||||
// rename this variable, you will also need to rename the namespace below.
|
||||
@@ -15,8 +15,8 @@ const routes = {
|
||||
common,
|
||||
// Home page
|
||||
home,
|
||||
// About us page, note the change from about-us to about_us.
|
||||
about_us
|
||||
// About us page, note the change from about-us to aboutUs.
|
||||
aboutUs,
|
||||
};
|
||||
|
||||
// Load Events
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export default {
|
||||
init() {
|
||||
// JavaScript to be fired on the about us page
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -4,5 +4,5 @@ export default {
|
||||
},
|
||||
finalize() {
|
||||
// JavaScript to be fired on all pages, after page specific JS is fired
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -4,5 +4,5 @@ export default {
|
||||
},
|
||||
finalize() {
|
||||
// JavaScript to be fired on the home page, after the init JS
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
5
assets/scripts/util/camelCase.js
Normal file
5
assets/scripts/util/camelCase.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// the most terrible camelizer on the internet, guaranteed!
|
||||
export default (str) => `${str.charAt(0).toLowerCase()}${str.replace(/[\W_]/g, '|').split('|')
|
||||
.map(part => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
|
||||
.join('')
|
||||
.slice(1)}`;
|
||||
@@ -1,8 +0,0 @@
|
||||
/* globals WEBPACK_PUBLIC_PATH */
|
||||
|
||||
// Dynamically set absolute public path from current protocol and host
|
||||
if (WEBPACK_PUBLIC_PATH !== false) {
|
||||
/* eslint-disable no-undef */
|
||||
__webpack_public_path__ = location.protocol + '//' + location.host + WEBPACK_PUBLIC_PATH;
|
||||
/*eslint-enable no-undef*/
|
||||
}
|
||||
@@ -6,6 +6,8 @@
|
||||
* replace the dash with an underscore when adding it to the object below.
|
||||
* ======================================================================== */
|
||||
|
||||
import camelCase from './camelCase';
|
||||
|
||||
// The routing fires all common scripts, followed by the page specific scripts.
|
||||
// Add additional events for more control over timing e.g. a finalize event
|
||||
export default class Router {
|
||||
@@ -25,10 +27,15 @@ export default class Router {
|
||||
this.fire('common');
|
||||
|
||||
// Fire page-specific init JS, and then finalize JS
|
||||
document.body.className.replace(/-/g, '_').split(/\s+/).forEach((className) => {
|
||||
this.fire(className);
|
||||
this.fire(className, 'finalize');
|
||||
});
|
||||
document.body.className
|
||||
.toLowerCase()
|
||||
.replace(/-/g, '_')
|
||||
.split(/\s+/)
|
||||
.map(camelCase)
|
||||
.forEach((className) => {
|
||||
this.fire(className);
|
||||
this.fire(className, 'finalize');
|
||||
});
|
||||
|
||||
// Fire common finalize JS
|
||||
this.fire('common', 'finalize');
|
||||
|
||||
Reference in New Issue
Block a user