Fix webpack HMR

This commit is contained in:
QWp6t
2016-09-11 11:39:48 -07:00
parent 3516629add
commit 10899cf2cd
11 changed files with 154 additions and 53 deletions

View File

@@ -1,34 +1,17 @@
const AssetsPlugin = require('assets-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const cssnano = require('cssnano');
const path = require('path');
const processOutput = require('./util/assetsPluginProcessOutput');
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,
processOutput,
}),
new OptimizeCssAssetsPlugin({
cssProcessor: cssnano,