我目前正在使用带有自定义 cra 的 react-app-rewired。目前,npm start
可以工作,但npm run build
会出现以下错误。
Error: You forgot to add 'mini-css-extract-plugin' plugin
不完全确定发生了什么,这是我的 config-overrides.js 文件。我尝试在此处添加插件,但由于某种原因无法正常工作,并且我继续收到此错误。
// Overriding CreateReactApp settings, ref: https://github.com/arackaf/customize-cra
const {
override,
fixBabelImports,
addLessLoader,
useEslintRc,
addDecoratorsLegacy,
useBabelRc,
addWebpackPlugin
} = require('customize-cra')
// eslint config
const eslintConfig = require('./.eslintrc.js');
const useEslintConfig = configRules => config => {
config.module.rules = config.module.rules.map(
rule => {
// Only target rules that have defined a `useEslintrc` parameter in their options
if (rule.use && rule.use.some(use => use.options && use.options.useEslintrc !== void 0)) {
const ruleUse = rule.use[0]
const baseOptions = ruleUse.options
const baseConfig = baseOptions.baseConfig || {}
ruleUse.options = {
useEslintrc: false,
ignore: true,
baseConfig: { ...baseConfig, ...configRules },
}
return rule
// Rule not using eslint. Do not modify.
} else {
return rule
}
}
);
return config;
}
module.exports = override(
addDecoratorsLegacy(),
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css', // dont use true
}),
// eslint-disable-next-line react-hooks/rules-of-hooks
useEslintRc(),
addLessLoader({
lessOptions: {
javascriptEnabled: true,
},
}),
// eslint-disable-next-line react-hooks/rules-of-hooks
useEslintConfig(eslintConfig),
// eslint-disable-next-line react-hooks/rules-of-hooks
useBabelRc(),
);
知道为什么吗?