如何添加Webpack插件以进行重新布线

我将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;
  }
);
hzhgch 回答:如何添加Webpack插件以进行重新布线

由于错误:

  

目前仅支持localesToKeepignoreInvalidLocales选项

尝试将您的代码从localeToKeep更改为localesToKeep。与s。

,

根据this issuecustomize-cra添加插件的正确方法是:

const MomentLocalesPlugin = require('moment-locales-webpack-plugin');

const addMomentLocalesPlugin = config => {
  config.plugins.push(new MomentLocalesPlugin());
  return config;
}

module.exports = override(
  addMomentLocalesPlugin,//...
)

如果您只想在软件包中保留几种语言,则可以尝试:

new MomentLocalesPlugin({ localesToKeep: ['es-us','pt'] })

代替

new MomentLocalesPlugin()
本文链接:https://www.f2er.com/3093968.html

大家都在问