Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142239

how to add webpack plugin to react-rewired

$
0
0

I use rca with react-rewired wrapper. To add custom configuration to webpack I created config-overrides.js file where I store my config settings. I added an babel-plugin-import and it was pretty easy. But now I want to use moment-locales-webpack-plugin to configure only one locale in my app to cut off app's weight.

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'] }),
);

After yarn start it shows me:

Failed to compile.

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

Can you help me with that please?

UPDATE I find out how to add a rule to override function, but still can't make it work with only 1 locale.

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', {
    libraryName: 'antd',
    libraryDirectory: 'es',
  }),
  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;
  }
);

Viewing all articles
Browse latest Browse all 142239

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>