我收到来自外部模块的编译警告。这导致我的构建失败,而且很烦人:
WARNING in ./node_modules/@private_team/library/styles/css/min/beam.min.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[0].oneOf[5].use[2]!./node_modules/@private_team/library/styles/css/min/beam.min.css) Module Warning (from ./node_modules/postcss-loader/dist/cjs.js): Warning
(1206:125827) autoprefixer: end value has mixed support, consider using flex-end instead
我正在开发一个由 create-react-app 启动的项目,现在正在运行react-scripts 5,它在底层使用了 webpack 5。我们正在使用craco自定义一些东西,这样我就可以在我的 webpack 配置中添加一些自定义内容。我的 craco.config.js 如下所示:
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
module.exports = {
webpack: {
resolve: {
extensions: [".ts", ".tsx", ".jsx", ".js"]
},
// the @private_team/library package was causing errors, which this fixed:
alias: {
"react/jsx-runtime": "react/jsx-runtime.js",
"react/jsx-dev-runtime": "react/jsx-dev-runtime.js"
},
// this is what webpack says to add, but its not helping
ignoreWarnings: [
{
message: /autoprefixer/
}
],
plugins: [
new NodePolyfillPlugin({
excludeAliases: ["console"]
})
]
},
plugins: [
...
]
};
我尝试在此处添加 ignoreWarnings
,但无论我使用什么变体,这些警告仍然存在于我的控制台中。我尝试过类似的变体:
ignoreWarnings: [
{
text: /flex/
}
],
ignoreWarnings: [
{
module: /node_modules/
}
],
ignoreWarnings: [
{
module: /.css&/
}
],
ignoreWarnings: [/autoprefixer/],
似乎无论我尝试什么,ignoreWarnings
都没有响应。我知道 craco.config.js 文件正在被读取,因为 alias
属性对我遇到的其他一些问题产生了积极的影响。
这里出了什么问题?这是一个克拉科问题吗?网页包问题?如何正确忽略这些警告?
最佳答案
事实证明我问得太早了。使用 CRACO 执行此操作的方法是将其添加到 configure
属性中:
module.exports = {
webpack: {
...,
configure: {
ignoreWarnings: [{ module: /.css$/ }]
},
},
...
};
我会将其留在这里,以防万一它可能对其他人有所帮助。
关于javascript - ignoreWarnings 对 CRACO 和 webpack 5 没有影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76150798/