我尝试使用webpack-dll-bundle-plugin将供应商与应用程序分开。它就像一个魅力:)
希望它有所帮助。
示例 webpack.config.js
const path = require('path');
const join = path.join.bind(path, __dirname);
const DllBundlesPlugin = require('webpack-dll-bundles-plugin').DllBundlesPlugin;
const pkg = require('./package.json');
const webpack = require('webpack');
module.exports = {
entry: {
main: './src/scripts/main.js'
},
output: {
path: path.resolve('./client'),
filename: '[name].js',
publicPath: '/client/',
chunkFilename: '[name].js'
},
cache: true,
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader',
// exclude: [path.join(__dirname, 'node_modules'), path.join(__dirname, './src', 'scripts', 'routes')],
exclude: [path.join(__dirname, 'node_modules')],
query: {
cacheDirectory: true,
presets: ['react', 'es2015'],
compact: false
}
}
]
},
plugins: [
new DllBundlesPlugin({
bundles: {
vendor: Object.keys(pkg.dependencies)
},
dllDir: join('client', 'vendor'),
webpackConfig: {
plugins: [
new webpack.optimize.UglifyJsPlugin({
comments: false
})
]
}
})
],
resolve: {}
};
包.json:
"dependencies": {
"classnames": "^2.2.5",
"es6-map": "^0.1.4",
"es6-promise": "^4.0.5",
"file-saver": "^1.3.3",
"guid": "0.0.12",
"jquery": "^3.1.1",
"lodash": "^4.17.4",
"moment": "^2.14.1",
"prop-types": "^15.6.0",
"react": "^15.4.2",
"react-addons-transition-group": "^15.4.2",
"react-dom": "^15.4.2",
"react-draggable-tab": "^0.8.1",
"xml-writer": "^1.7.0"
}