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:
40
assets/build/webpack.config.production.js
Normal file
40
assets/build/webpack.config.production.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
const AssetsPlugin = require('assets-webpack-plugin');
|
||||
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
||||
const cssnano = require('cssnano');
|
||||
const path = require('path');
|
||||
|
||||
const config = require('./config');
|
||||
|
||||
/**
|
||||
* Process AssetsPlugin output and format it
|
||||
* for Sage: {"[name].[ext]":"[name]_[hash].[ext]"}
|
||||
* @param {Object} assets passed by processOutput
|
||||
* @return {String} JSON
|
||||
*/
|
||||
const assetsPluginProcessOutput = (assets) => {
|
||||
const results = {};
|
||||
Object.keys(assets).forEach(name => {
|
||||
Object.keys(assets[name]).forEach(ext => {
|
||||
const filename = `${path.dirname(assets[name][ext])}/${path.basename(`${name}.${ext}`)}`;
|
||||
results[filename] = assets[name][ext];
|
||||
});
|
||||
});
|
||||
return JSON.stringify(results);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
new AssetsPlugin({
|
||||
path: config.paths.dist,
|
||||
filename: 'assets.json',
|
||||
fullPath: false,
|
||||
processOutput: assetsPluginProcessOutput,
|
||||
}),
|
||||
new OptimizeCssAssetsPlugin({
|
||||
cssProcessor: cssnano,
|
||||
cssProcessorOptions: { discardComments: { removeAll: true } },
|
||||
canPrint: true,
|
||||
}),
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user