排除生产构建中的资产 [英] Exclude assets in production build
问题描述
我有一些仅在开发过程中需要的资产(图像、样式)(ng serve).这些资产不得包含在生产版本中.在生产中,这些资产由 CDN 提供.
I have some assets (images, styles) which I only need during development (ng serve). These assets must not be included in the production build. In production these assets are provided by a CDN.
我需要:
- ng serve 应该提供文件夹中包含的文件./assets-non-build
但是:
- ng build 不应包含文件夹 ./assets-non-build 在最终构建
我在 SO 上解决了 10 个类似的问题,在 github 上解决了 5 个问题,它们都处理排除文件,但没有一个解决了我的情况.
I have worked through 10 similar questions here on SO and 5 issues on github, they all deal with excluding files, but none solved my situation.
推荐答案
在你的 angular.json
里面有一个配置对象 projects.{project-name}.architect.build.configurations代码>.
Inside your angular.json
there is a configurations object projects.{project-name}.architect.build.configurations
.
将 prod 条目中的 assets
设置为 []
Set the assets
inside the prod entry to []
"production": {
//...
"assets": []
}
虽然这是未经测试的,但从我从配置文件中了解到的情况来看,这应该是可能的.
This is untested though, but by judging from what I know from the configuration file, this should be possible.
这将使任何构建和服务与生产标志一起排除资产.如果您真的希望所有构建,无论环境如何,都无需资产进行构建,您可以从 projects.{project-name}.architect.build.options
移动 assets
数组> 到 projects.{project-name}.architect.serve.options
并将 build
中的一个设置为空数组.
This will make any build and serve with the production flag to exclude the assets. If you really want all the builds, no matter the environment, to build without assets, you move the assets
array from projects.{project-name}.architect.build.options
to the projects.{project-name}.architect.serve.options
and set the one in build
to an empty array.
这篇关于排除生产构建中的资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!