我已经使用require.ensure
解决了这个问题,但我的代码对于所有这些reqiure.ensure
都很难看。我真正想要的是将react-dom
和jquery
提取到单独的common.js
文件中。但我得到的只是代码重复= /
这是我的webpack.config
context: __dirname+ "/resources/app",
entry: {
main: './main.jsx',
common: ["jquery","react","react-dom"]
},
progress: true,
output: {
publicPath: "/js/",
path: __dirname+"/public/js",
filename: '[name].js',
library:"[name]"
},
这是我的插件:
plugins: [
new webpack.optimize.CommonsChunkPlugin({ name: "common" }),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.NoErrorsPlugin(),
]
Asset Size Chunks Chunk Names
main.js 244 kB 0 [emitted] main
common.js 232 kB 1, 2 [emitted] common
当我import $ from 'jquery'
所有jquery代码添加到main.jsx
jquery
模块刚刚添加到main.js
,即使它已经存在于common.js中
Asset Size Chunks Chunk Names
main.js 330 kB 0 [emitted] main
common.js 232 kB 1, 2 [emitted] common