When running npm run build, the run-s command executes the "env:prod" script in a separate command than the "build:css" command, so NODE_ENV=production is not persisted into the postcss call. I suggest adding "cross-env NODE_ENV=production" directly into the build:css script, e.g.:
"scripts": {
"start": "run-p watch:css react-scripts:start",
"build": "run-s build:css react-scripts:build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"build:css": "cross-env NODE_ENV=production postcss src/styles/tailwind.css -o src/styles/index.css",
"watch:css": "cross-env NODE_ENV=development postcss src/styles/tailwind.css -o src/styles/index.css --watch",
"react-scripts:start": "sleep 5 && react-scripts start",
"react-scripts:build": "react-scripts build"
},
This is the file size change after making this modification to package.json for a vanilla project using cra-template-tailwindcss-typescript:
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
39.39 KB build/static/js/2.f2e7b3c8.chunk.js
2.45 KB build/static/js/main.559c7be3.chunk.js
1.69 KB (-97.8 KB) build/static/css/main.808035e1.chunk.css
783 B build/static/js/runtime-main.3cf3366c.js
The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
You may serve it with a static server:
yarn global add serve
serve -s build
Find out more about deployment here:
bit.ly/CRA-deploy
Done in 13.71s.