在生产构建中排除资产

编程入门 行业动态 更新时间:2024-10-23 07:33:09
本文介绍了在生产构建中排除资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

在生产构建中排除资产

本文发布于:2023-11-16 17:02:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:资产

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!