使用webpack 5构建时,我得到错误:
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.devtool should match pattern "^(inline-|hidden-|eval-)?(nosources-)?(cheap-(module-)?)?source-map$".
BREAKING CHANGE since webpack 5: The devtool option is more strict.
Please strictly follow the order of the keywords in the pattern.
然而,在我的webpack.config.js中,我有一个设置:
devtool: 'eval-cheap-source-map',
我也尝试过eval
作为价值,但也不起作用,尽管这个网站(https://webpack.js.org/configuration/devtool/)似乎表明它应该这样做。我不明白,这里出了什么问题?
编辑:我的webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/app.js',
plugins: [
new HtmlWebpackPlugin({
title: 'MyApp',
}),
],
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'var',
library: 'MyApp'
},
resolve:{
alias:{
EVENTS: path.resolve(__dirname, "src/events"),
MODELS: path.resolve(__dirname, "src/models"),
GUI: path.resolve(__dirname, "src/gui"),
HELPER: path.resolve(__dirname, "src/helper")
}
},
devtool: 'eval-cheap-source-map',
devServer: {
watchContentBase: true,
contentBase: path.resolve(__dirname, 'dist'),
port: 9000
},
module: {
rules: [
{
test:/.css$/,
use:['style-loader', 'css-loader']
}
]
},
}
我的构建脚本是webpack src/app.js -d --watch
从构建脚本中删除-d
参数。-d
代表devtool,但在命令中它后面没有参数值。