【发布时间】:2021-07-30 21:57:51
【问题描述】:
我想在我的 react 应用程序中添加一个bundle-analyzer,当开发人员运行 yarn analyze 时,package.json 已设置为 "analyze": "craco build --analyze-only"。
我确实阅读了craco 的手册,但没有找到任何解决方案。我目前的配置如下:
const progressBar = require('./progressBar.webpack.config');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
module.exports = {
reactScriptsVersion: 'react-scripts' /* (default value) */,
webpack: {
alias: {},
plugins: {
add: [progressBar()] /* An array of plugins */
},
configure: (webpackConfig, { env, paths }) => {
if (env === 'production') {
webpackConfig.plugins.push(new BundleAnalyzerPlugin());
}
return webpackConfig;
}
}
};
我们如何将参数传递给它?
【问题讨论】:
-
你的意思是要读取配置文件中
--analyze-only的参数吗? -
@tmhao2005 是的,我想访问它,所以当这个参数被传递时,在 `configure: (webpackConfig, { env, paths }) => {}` 部分做一些事情
标签: reactjs webpack create-react-app craco