Skip to content

Instantly share code, notes, and snippets.

@Arguseye
Created September 28, 2017 09:26
Show Gist options
  • Select an option

  • Save Arguseye/a5fb97292bb2526915a062a8484d1e3d to your computer and use it in GitHub Desktop.

Select an option

Save Arguseye/a5fb97292bb2526915a062a8484d1e3d to your computer and use it in GitHub Desktop.
CommonsChunkPlugin
// src/common.js
console.log('common file');
// src/pageA.js
const _ = require('lodash');
require('./common');
console.log(_.first([1, 2, 3]));
// src/pageB.js
const _ = require('lodash');
require('./common.js');
function abc() {
console.log('');
}
console.log(_.flatten([1, [2, 3, [4]]], true));
const path = require('path');
const webpack = require('webpack');
const srcDir = path.resolve(__dirname, 'src');
const outputDir = path.resolve(__dirname, 'dist');
const CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
module.exports = {
entry: {
'pageA': './pageA.js',
'pageB': './pageB.js',
'vendor': ['jquery']
},
context: srcDir,
output: {
path: outputDir,
filename: 'js/[name].[hash].js',
chunkFilename: 'js/[chunkhash:8].chunk.js'
},
plugins: [
new webpack.NamedModulesPlugin(),
new CommonsChunkPlugin({
name: 'common',
minChunks: 2 // number or Infinity
}),
new CommonsChunkPlugin({name: 'webpack_runtime', minChunks: Infinity})
],
resolve: {
extensions: ['.js'],
alias: {
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment