简体   繁体   中英

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.

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?

I can see in node_modules/react-scripts/config/webpack.config.js that the build is set by this code:

const isEnvDevelopment = webpackEnv === 'development'
const isEnvProduction = webpackEnv === 'production'; 

if I added a build-dev in the package.json, how would I make webpackEnv 'development'?

Hack valid (at least used) for React 17.0.2 & Co.

Open the file 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM