我将rca与react-rewired包装器一起使用。要将自定义配置添加到webpack,我创建了config-overrides.js
文件,用于存储配置设置。我添加了babel-plugin-import
,这非常简单。但是现在我想使用moment-locales-webpack-plugin
在我的应用程序中仅配置一种语言环境以减轻应用程序的重量。
const { override,fixBabelImports,addWebpackPlugin } = require('customize-cra');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
module.exports = override(
fixBabelImports('import',{
libraryName: 'antd',libraryDirectory: 'es',}),addWebpackPlugin(MomentLocalesPlugin,{ localeToKeep: ['us'] }),);
yarn start
之后显示给我:
无法编译。
MomentLocalesPlugin: received unknown options: _pluginCompat,hooks,name,parentCompilation,outputPath,outputFileSystem,inputFileSystem,recordsInputPath,recordsOutputPath,records,removedFiles,fileTimestamps,contextT
imestamps,resolverFactory,infrastructureLogger,resolvers,options,context,requestShortener,running,watchMode,_assetEmittingSourceCache,_assetEmittingWrittenFiles,watchFileSystem. Only `localesToKeep` and `ignoreInva
lidLocales` options are supported at the moment
你能帮我吗?
更新
我发现了如何向override
函数中添加规则,但仍然无法使其仅在1种语言环境下工作。
const { override,fixBabelImports } = require('customize-cra');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const path = require('path');
module.exports = override(
fixBabelImports('import',function(config) {
const alias = config.resolve.alias || {};
alias['@ant-design/icons/lib/dist$'] = path.resolve(__dirname,'./src/icons.js');
config.resolve.alias = alias;
config.plugins = (config.plugins || []).concat([
new MomentLocalesPlugin(),new BundleAnalyzerPlugin(),]);
return config;
}
);