[英]react-scripts build an unminified version
How do can you get the "build": "react-scripts build" in a package.json to build an unminified version of the code.如何在 package.json 中获取 "build": "react-scripts build" 以构建代码的未缩小版本。
I have looked at the answers in this post but they are all too complicated:我看过这篇文章中的答案,但它们都太复杂了:
How to build a production version of React without minification? 如何在不缩小的情况下构建 React 的生产版本?
I can see in node_modules/react-scripts/config/webpack.config.js that the build is set by this code:我可以在 node_modules/react-scripts/config/webpack.config.js 中看到构建是由这段代码设置的:
const isEnvDevelopment = webpackEnv === 'development'
const isEnvProduction = webpackEnv === 'production';
if I added a build-dev in the package.json, how would I make webpackEnv 'development'?如果我在 package.json 中添加了一个构建开发,我将如何使 webpackEnv 成为“开发”?
Hack valid (at least used) for React 17.0.2 & Co. Hack 对 React 17.0.2 & Co. 有效(至少使用过)。
Open the file node_modules/react-scripts/scripts/build.js
打开文件
node_modules/react-scripts/scripts/build.js
Locate the lines saying找到行说
process.env.BABEL_ENV = 'production';
process.env.NODE_ENV = 'production';
Change to改成
process.env.BABEL_ENV = 'development';
process.env.NODE_ENV = 'development';
Locate the line saying找到行说
const config = configFactory('production');
Change to改成
const config = configFactory('development');
If the error is disturbing your env, then comment out如果错误干扰了您的环境,请注释掉
printFileSizesAfterBuild(
stats,
previousFileSizes,
paths.appBuild,
WARN_AFTER_BUNDLE_GZIP_SIZE,
WARN_AFTER_CHUNK_GZIP_SIZE
);
to到
/*
printFileSizesAfterBuild(
stats,
previousFileSizes,
paths.appBuild,
WARN_AFTER_BUNDLE_GZIP_SIZE,
WARN_AFTER_CHUNK_GZIP_SIZE
);
*/
Then (adjust the file copying to your local environment):然后(调整文件复制到您的本地环境):
npm run build
scp -r build/* dist/* target:/webroot
Good luck.祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.