之后npm install jquery-migrate
,我可以只require('jquery-migrate');
在主scripts.js
文件中。这工作正常:
console.log(jQuery.migrateVersion); // JQMIGRATE: Migrate is installed with logging active, version 3.0.0
现在,我想设置它,以便生产版本上不存在 jquery-migrate。
webpack.config.js:
var dev = process.env.NODE_ENV !== 'prod';
var webpack = require('webpack');
var dist = '/dist/js';
module.exports = {
context: __dirname,
entry: __dirname + '/src/js/scripts.js',
output: {
path: __dirname + dist,
filename: 'scripts.js'
},
resolve: {
alias: {
'jquery': 'jquery/src/jquery',
'jquery-migrate': 'jquery-migrate'
}
},
plugins: dev ? [
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery',
'jquery-migrate': 'jquery-migrate'
})
] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery'
})
]
};
这不起作用:
console.log(jQuery.migrateVersion); // Undefined
如何从 webpack.config 加载 jquery-migrate?