[英]npm run build production does not distribute the production
I have a problem with my Angular project.我的 Angular 项目有问题。 Especially on the build of the project.
特别是在项目的构建上。
When I build my Angular poject with当我构建 Angular 项目时
ng build
it creates the dist-folder with the correct build.它使用正确的构建创建 dist 文件夹。 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:当我使用 NPM (由构建服务器使用)时,我使用这个:
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
).我有一个 environment.prod.ts (
production = true
)。 It is set in the Angular.json.它设置在 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 npm run build
应该在package.json
有脚本,看看那里,也许在脚本中添加一行
{
...
scripts: {
"build": "ng build --prod"
},
...
}
this should do the trick 这应该可以解决问题
What you can do is update the build script in the package.json
as 您可以做的是将
package.json
的构建脚本更新为
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
然后您可以将参数传递给
ng build
例如ng build --prod
You could also use --
to separate the params passed to npm command itself and params passed to your script. 您还可以使用
--
分隔传递给npm命令本身的参数和传递给脚本的参数。 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 npm 运行构建 -- --configuration=production
or this if it's "prod":或者如果它是“产品”:
npm run build -- --configuration=prod npm 运行构建 -- --configuration=prod
if you don't specify the "configuration" parameter name you may see this error:如果您不指定“配置”参数名称,您可能会看到此错误:
npm run build -- --prod npm 运行构建 -- --prod
Error: Unknown argument: prod错误:未知参数:prod
npm run build -- --production npm 运行构建--生产
Error: Unknown argument: production错误:未知参数:生产
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.