pvpokemon/webpack.config.options.js
2019-05-14 17:02:24 -04:00

92 lines
3.3 KiB
JavaScript

const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const WebpackShellPlugin = require('webpack-shell-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
const outputDirectory = 'dist';
module.exports.outputDirectory = outputDirectory;
function recursiveIssuer(m) {
if (m.issuer) {
return recursiveIssuer(m.issuer);
} else if (m.name) {
return m.name;
} else {
return false;
}
}
module.exports.getOptimizations = function () {
return {
splitChunks: {
cacheGroups: {
commons: {
name: 'commons',
filename: 'commons-bundle.js',
chunks: 'initial',
// (the filename of the commons chunk)
minChunks: 3,
},
globalStyles: {
name: 'global',
test: (moodule, chunks) => {
return moodule.constructor.name === 'CssModule' && recursiveIssuer(moodule) === 'global';
},
chunks: 'all',
enforce: true,
},
appStyles: {
name: 'app',
test: (moodule, chunks) => {
return moodule.constructor.name === 'CssModule' && recursiveIssuer(moodule) !== 'global';
},
chunks: 'all',
enforce: true,
},
}
}
};
// new webpack.optimize.CommonsChunkPlugin({
// name: 'vendor',
// filename: 'vendor-bundle.js',
// minChunks: function (module) {
// return (module.context || '').indexOf('node_modules') !== -1;
// }
// }),
// new webpack.optimize.CommonsChunkPlugin({
// // (the commons chunk name)
// name: 'commons',
// // (the filename of the commons chunk)
// filename: 'js/commons-bundle.js',
// minChunks: function(module, count) {
// // (Modules must be shared between 2 entries or be included by the globally-exposed-dependencies-bundle)
// return /*(module.context || '').indexOf('node_modules') === -1 && */count >= 2;
// },
// }),
};
module.exports.getPlugins = function (env) {
env = env || {};
return [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment\/min$/),
new webpack.optimize.ModuleConcatenationPlugin(), // --display-optimization-bailout
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: '[name].css',
// filename: (getPath) => {
// // output the css into the css directory instead of the js directory (where the bundles are)
// return 'css/' + getPath('[name].tmp.css').replace(/^js\//, '');
// },
// chunkFilename: "[id].css"
}),
new WorkboxPlugin.GenerateSW({
// these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling "old" SWs to hang around
clientsClaim: true,
skipWaiting: true
})
];
};