[Webpack 2] Chunking common modules from multiple apps with the Webpack CommonsChunkPlugin

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Webpack 2] Chunking common modules from multiple apps with the Webpack CommonsChunkPlugin相关的知识,希望对你有一定的参考价值。

If you have a multi-page application (as opposed to a single page app), you’re likely sharing modules between these pages. By chunking these common modules into a single common bundle, you can leverage the browser cache much more powerfully. In this lesson we’ll use webpack’s CommonsChunkPlugin to easily share common modules between apps.

 

const webpack = require(‘webpack‘)
const {resolve} = require(‘path‘)
module.exports = env => {
  return {
    entry: {
      app: ‘./js/app.js‘,
      animalFacts: ‘./animal-facts/js/app.js‘,
    },
    output: {
      filename: ‘bundle.[name].js‘,
      path: resolve(__dirname, ‘dist‘),
      pathinfo: !env.prod,
    },
    context: resolve(__dirname, ‘src‘),
    devtool: env.prod ? ‘source-map‘ : ‘eval‘,
    bail: env.prod,
    module: {
      loaders: [
        {test: /\.js$/, loader: ‘babel!eslint‘, exclude: /node_modules/},
        {test: /\.css$/, loader: ‘style!css‘},
      ],
    },
    plugins: [
      env.test ? undefined : new webpack.optimize.CommonsChunkPlugin({
        name: ‘common‘,
        filename: ‘bundle.common.js‘,
        chunks: [‘app‘, ‘animalFacts‘]
      }),
    ].filter(p => !!p),
  }
}

 

以上是关于[Webpack 2] Chunking common modules from multiple apps with the Webpack CommonsChunkPlugin的主要内容,如果未能解决你的问题,请参考以下文章

配置过max_allowed_packet依然 Error Chunking during uploading files to db..

vue+webpack新项目总结1

每天One Linux 命令 | comm:比较两个已排过序的文件

如何获得comm输出的第一列?

Linux:- comm命令的妙用

comm diff 文件对比