admin管理员组文章数量:1405581
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 pile.
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;
}
);
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 pile.
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;
}
);
Share
Improve this question
edited Nov 16, 2019 at 13:44
poltorin
asked Nov 15, 2019 at 16:29
poltorinpoltorin
3022 gold badges4 silver badges13 bronze badges
2 Answers
Reset to default 3The right way to add a plugin to customize-cra
according to this issue is:
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const addMomentLocalesPlugin = config => {
config.plugins.push(new MomentLocalesPlugin());
return config;
}
module.exports = override(
addMomentLocalesPlugin,
//...
)
And if you want to keep only a few languages in your bundle, you can try:
new MomentLocalesPlugin({ localesToKeep: ['es-us', 'pt'] })
Instead of
new MomentLocalesPlugin()
From the error:
Only
localesToKeep
andignoreInvalidLocales
options are supported at the moment
Try changing your code from localeToKeep
to localesToKeep
. With the s.
本文标签: javascripthow to add webpack plugin to reactrewiredStack Overflow
版权声明:本文标题:javascript - how to add webpack plugin to react-rewired - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744285826a2598872.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论