webpack
Monday, April 24, 2023
javascript
// webpack4
const merge = require('webpack-merge')
//webpack5
const {merge} = require('webpack-merge')
javascript
output: {
clean: true,
},
javascript
DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_HASH] DeprecationWarning: [hash] is now [fullhash] (also consider using [chunkhash] or [contenthash], see documentation for details)
javascript
// before
filename: path.join('static', project.version, "[name][hash].bundle.js")
// after
filename: path.join('static', project.version, "[name][chunkhash].bundle.js")
javascript
// 设置extractComments 为 falas
minimizer: [
new TerserPlugin({
extractComments: false
})
]
javascript
// before 4
devtool: 'cheap-module-eval-source-map'
after 5
devtool: 'eval-cheap-module-source-map'
javascript
// before
devServer: {
historyApiFallback: true,
disableHostCheck: true,
contentBase: './'
}
after
devServer: {
historyApiFallback: true,
allowedHosts: "all",
static: './'
},
javascript
// 报错内容
export 'default' (imported as 'mod') was not found in '-!../../../../node_modules/mini-css-extract-plugin/dist/loader.js
// 原因大概是因为我们在项目中引入的时候都是 import './index.css' 而没有导出它
// 不符合esModule的规范 忽略它就好了
// 给MiniCssExtractPlugin.loader添加参数 设置esModule为false
{
test: /\.s?css$/,
exclude: '/node_modules/',
use: [{
loader: MiniCssExtractPlugin.loader,
options: {
esModule: false
}
}, 'css-loader', 'postcss-loader', 'sass-loader',]
}