RE: How to get a production build with Liferay for react? Liferay 7.2

Marco Portillo, modified 5 Years ago. New Member Posts: 3 Join Date: 5/23/19 Recent Posts
Hi,I have been searching on the internet for a few hours, but i cannot find anything about it. I just have this, which for development is fine, but I need to deploy my portlets as a production build as well, I always use:
npm run build OR npm run deploy
but that just keeps building a normal .jar file in dev mode, and I need one for production. If I check my portlets with react developer tools in Chrome, I have this message:image
What to do? Any ideas?
thumbnail
Christoph Rabel, modified 5 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
I am not really a react guy, but check the package.json file.
You usually need to have an extra build target for that, and usually implement it by adding some parameters to the npm scripts, eg. in our case with webpack it looks this way: (npm run production)
"production": "cross-env NODE_ENV=production ./node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config webpack/config/webpack.prod.js",

I hope, there is already a fitting target in in the package.json. If not, you could try to set the environment variable as we do it. But the build has to support that. The script has to check the mode and use e.g. TerserPlugin or something like that in that case.