Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude assets in production build

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.

I need:

  • ng serve should serve files contained in the folder ./assets-non-build

but:

  • ng build should not inculde the folder ./assets-non-build in the final build

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.

like image 277
Tobias Gassmann Avatar asked Nov 14 '18 10:11

Tobias Gassmann


People also ask

How do I exclude assets from my builds?

If you require assets for your tools, like images or models, create a resource inside your Editor folder to exclude the assets from any builds you make. You can get a similar effect by using assembly definitions. To do that, create a folder with the scripts you want to exclude and create an assembly definition asset inside.

How to build a project without any assets?

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.

How to exclude scripts from a build?

You can get a similar effect by using assembly definitions. To do that, create a folder with the scripts you want to exclude and create an assembly definition asset inside. On the inspector in the included platforms section, only select Editor. This way, builds won't include the scripts.

How to exclude assets from a project in angular?

Inside your angular.json there is a configurations object projects. {project-name}.architect.build.configurations. This is untested though, but by judging from what I know from the configuration file, this should be possible. This will make any build and serve with the production flag to exclude the assets.


Video Answer


1 Answers

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.

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.

like image 129
Poul Kruijt Avatar answered Oct 10 '22 04:10

Poul Kruijt