22

从 Webpack 4 迁移到 Webpack 5 时,使用devtool空值时出现错误(仅在生产模式下)。

module.exports = {
    devtool: isProd ? '' : 'source-map',
    // entry: ...
    // output: ...
    // module: ...
}

控制台中的消息:

ValidationError: 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.

任何想法如何在生产模式下避免源映射?在那里输入什么?

4

2 回答 2

41

回答自己的问题!剧透:false

module.exports = {
    devtool: isProd ? false : 'source-map',
}

在 Webpack 4 中,可以用空字符串来赋值。webpack 5 更加严格。Webpacks 开发工具配置

于 2020-07-01T07:42:46.570 回答
0

不知何故,我"source-map"有一个 # 就像"#source-map"导致这个错误一样。#通过从字符串中删除来解决错误。

前:

devtool: (config.enabled.sourceMaps ? '#source-map' : false)

后:

devtool: (config.enabled.sourceMaps ? 'source-map' : false)
于 2021-12-30T00:45:24.743 回答