在生产构建中排除资产 [英] Exclude assets in production build

查看:52
本文介绍了在生产构建中排除资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些资产(图像,样式)仅在开发(服务时)时需要.这些资产不得包含在生产版本中.在生产中,这些资产由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.

将产品条目中的资产设置为 []

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.

这将进行任何构建并与生产标记一起使用以排除资产.如果您确实希望所有构建(无论环境如何)都没有资产,则可以将 assets 数组从 projects.{project-name} .architect.build.options 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆