How to build a production version of React without minification?

前端 未结 3 583
遥遥无期
遥遥无期 2020-12-15 20:31

Background

I\'ve been following more or less the official guide to setup a local dev environment with react and it seems to use create-react-app, whic

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 20:53

    I wanted the unobfuscated code of a React app - mostly of curiosity, I had the source - while having the job of rewriting it in Angular (producing a far more maintainable app 5% of the size and 1% dependencies).

    I've never used React but discovered by modifying the file

    /node_modules/react-scripts/config/webpack.config.prod.js

    and replacing the large optimization config item, under module.exports, with the following...

    module.exports = {...
    
        optimization: {
                minimize: false,
                splitChunks: {
                    chunks: 'all',
                    name: true
                },
                runtimeChunk: true
            },
    

    npm run build built unobfuscated, readable code that ran as expected, using no other modifications. Used Gitbash only with the commands npm install, npm run build and npm start - Just thought someone may find that useful.

    I don't recommend this because the code you want is still wrapped in a webpack eval mess. It's easier to pick the useful bits from the source or just rebuild the app. At best, I got to see what a cluster react and webpack is.

提交回复
热议问题