Created
September 28, 2017 09:26
-
-
Save Arguseye/a5fb97292bb2526915a062a8484d1e3d to your computer and use it in GitHub Desktop.
CommonsChunkPlugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src/common.js | |
| console.log('common file'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src/pageA.js | |
| const _ = require('lodash'); | |
| require('./common'); | |
| console.log(_.first([1, 2, 3])); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src/pageB.js | |
| const _ = require('lodash'); | |
| require('./common.js'); | |
| function abc() { | |
| console.log(''); | |
| } | |
| console.log(_.flatten([1, [2, 3, [4]]], true)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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