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:
QWp6t
2016-09-04 19:13:16 -07:00
committed by GitHub
parent a69d57c547
commit f6bdc7b48c
22 changed files with 426 additions and 351 deletions

View File

@@ -1,5 +1,5 @@
import $ from 'jquery';
wp.customize('blogname', (value) => {
value.bind((to) => $('.brand').text(to))
value.bind((to) => $('.brand').text(to));
});

View File

@@ -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

View File

@@ -1,5 +1,5 @@
export default {
init() {
// JavaScript to be fired on the about us page
}
},
};

View File

@@ -4,5 +4,5 @@ export default {
},
finalize() {
// JavaScript to be fired on all pages, after page specific JS is fired
}
},
};

View File

@@ -4,5 +4,5 @@ export default {
},
finalize() {
// JavaScript to be fired on the home page, after the init JS
}
},
};

View 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)}`;

View File

@@ -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*/
}

View File

@@ -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');