I have a problem with my Angular project. Especially on the build of the project.
When I build my Angular poject with
ng build
it creates the dist-folder with the correct build. When I use the following command:
ng build --prod
it creates the production build (correct)
When I use NPM (used by build server) I use this:
run build
But I want the production build. Whatever I do, it doesn't work locally or on the buildserver. I used these:
npm run build --prod
npm run build --target=production
npm run build --environment=prod
npm run build --environment=production
npm run build --env=production
npm run build --env=prod
npm run build *projectname* --environment=production
npm run build *projectname* --env=production
npm run build *projectname* production
And probably a lot more. It just does not build the production!
I have a environment.prod.ts ( production = true
). It is set in the Angular.json. I have no clue what I am doing wrong.
npm run build
should have the script in the package.json
have a look there and maybe add the line in the scripts
{
...
scripts: {
"build": "ng build --prod"
},
...
}
this should do the trick
What you can do is update the build script in the package.json
as
scripts:{
"build": "npm run ng build --",
"ng": "ng"
}
--
allows you to pass arguments to a script.
Then you can pass the arguments to ng build
like ng build --prod
You could also use --
to separate the params passed to npm command itself and params passed to your script. So the correct syntax for your case would be:
npm run build -- --prod
Try this if your environment is "production":
npm run build -- --configuration=production
or this if it's "prod":
npm run build -- --configuration=prod
if you don't specify the "configuration" parameter name you may see this error:
npm run build -- --prod
Error: Unknown argument: prod
npm run build -- --production
Error: Unknown argument: production
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.