Webpack 5:devtool ValidationError,配置对象无效

jxct1oxe  于 9个月前  发布在  Webpack
关注(0)|答案(3)|浏览(124)

在从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.


有什么想法可以避免在生产模式下使用源代码Map吗?在那里输入什么?

ippsafx7

ippsafx71#

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

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

字符串
在Webpack 4中,可以使用空字符串来值此值。webpack 5更严格。Webpacks devtool configuration

sf6xfgos

sf6xfgos2#

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

之前:

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

字符串

之后:

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

inkz8wg9

inkz8wg93#

之前:devtool:“#source-map”之后:devtool:“source-map”

相关问题