首页 > 移动平台 > 详细

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

时间:2016-06-23 06:23:04      阅读:411      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/Answer1215/p/5609157.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!