I have an Angular application in an Nx workspace that is built using the @nx/angular:webpack-browser executor.
"build": {
"executor": "@nx/angular:webpack-browser",
...
}
This is a large application and requires NODE_OPTIONS=--max_old_space_size to be set to a larger value.
Until now I used set and export to set the value of this flag in Windows/Linux and then run the build command.
The first command was
set NODE_OPTIONS=--max_old_space_size=MY_VALUE`
and the second was
npm run build -- MY_APP
which translates to nx build.
I would like to get rid of the first command and set the flag from the project.json file. I tried with a custom executor and `cross-env' package, but no luck.
"node-options": {
"executor": "nx:run-commands",
"options": {
"command": "cross-env NODE_OPTIONS=--max_old_space_size=5000"
}
},
"build": {
"executor": "@nx/angular:webpack-browser",
"dependsOn": ["^build", "node-options"],
...
Is there a way to achieve this?
Nx will load environment variables from
.envfiles. It also supports a hierarchy of files.So just add
NODE_OPTIONS=--max_old_space_size=5000toapps/my-app/.envfor example