webpack4配置momet按需加载,每个文件依然有moment?
配置了moment按需加载
var webpackConfig = {
mode: 'development',
entry: {
index: './src/index.js',
another: './src/another-module.js',
},
output: {
filename: '[name].[contenthash].js',
},
plugins: [
// new CleanWebpackPlugin(['dist/*']) for < v2 versions of CleanWebpackPlugin
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'Caching',
template: './src/index.html',
}),
new LodashModuleReplacementPlugin(),
new webpack.ContextReplacementPlugin(
/moment[/\\]locale$/,
/zh-cn|es|zh-tw|ja/,
),
// new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
],
optimization: {
moduleIds: 'hashed',
runtimeChunk: 'single',
splitChunks: {
maxInitialRequests: 4,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: -10,
},
vendor1: {
name: 'vendor-antd',
test: (module) => {
return /[\\/]node_modules[\\/]@ant-design|antd/.test(module.context);
},
chunks: 'all',
priority: 2
},
},
},
},
module:{
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env','@babel/preset-react'],
plugins: [
'lodash',
["import", {
"libraryName": "antd",
// "libraryDirectory": "es",
// "style": "css" // `style: true` 会加载 less 文件
}]
],
}
}
},
{//antd样式
test: /\.css$/,
exclude: /src/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader",
options: {
importLoaders: 1
}
}
]
}
],
},
// externals: {
// lodash: {
// commonjs: 'lodash',
// commonjs2: 'lodash',
// amd: 'lodash',
// root: '_',
// },
// },
// optimization: {
// splitChunks: {
// chunks: 'all',
// },
// },
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论