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.
add a comment |
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.
Probably you need to exclude yourassetsfolder from angular.json configuration, Have you removed that?
– Pardeep Jain
Nov 14 '18 at 10:17
If I remove it from the angular.json, the files within that asset-folder wont be served by ng serve anymore ( I load them via an ajax-request)
– Tobias Gassmann
Nov 14 '18 at 10:17
Not tried yet, but there are two options one is for build and another one is for serve, so probably you need to set those as per requirements
– Pardeep Jain
Nov 14 '18 at 10:19
that sounds interesting! How do I set options for build and serve?
– Tobias Gassmann
Nov 14 '18 at 10:20
add a comment |
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.
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.
edited Nov 14 '18 at 10:21
jonrsharpe
78.1k11106216
78.1k11106216
asked Nov 14 '18 at 10:14
Tobias GassmannTobias Gassmann
3,96753363
3,96753363
Probably you need to exclude yourassetsfolder from angular.json configuration, Have you removed that?
– Pardeep Jain
Nov 14 '18 at 10:17
If I remove it from the angular.json, the files within that asset-folder wont be served by ng serve anymore ( I load them via an ajax-request)
– Tobias Gassmann
Nov 14 '18 at 10:17
Not tried yet, but there are two options one is for build and another one is for serve, so probably you need to set those as per requirements
– Pardeep Jain
Nov 14 '18 at 10:19
that sounds interesting! How do I set options for build and serve?
– Tobias Gassmann
Nov 14 '18 at 10:20
add a comment |
Probably you need to exclude yourassetsfolder from angular.json configuration, Have you removed that?
– Pardeep Jain
Nov 14 '18 at 10:17
If I remove it from the angular.json, the files within that asset-folder wont be served by ng serve anymore ( I load them via an ajax-request)
– Tobias Gassmann
Nov 14 '18 at 10:17
Not tried yet, but there are two options one is for build and another one is for serve, so probably you need to set those as per requirements
– Pardeep Jain
Nov 14 '18 at 10:19
that sounds interesting! How do I set options for build and serve?
– Tobias Gassmann
Nov 14 '18 at 10:20
Probably you need to exclude your
assets folder from angular.json configuration, Have you removed that?– Pardeep Jain
Nov 14 '18 at 10:17
Probably you need to exclude your
assets folder from angular.json configuration, Have you removed that?– Pardeep Jain
Nov 14 '18 at 10:17
If I remove it from the angular.json, the files within that asset-folder wont be served by ng serve anymore ( I load them via an ajax-request)
– Tobias Gassmann
Nov 14 '18 at 10:17
If I remove it from the angular.json, the files within that asset-folder wont be served by ng serve anymore ( I load them via an ajax-request)
– Tobias Gassmann
Nov 14 '18 at 10:17
Not tried yet, but there are two options one is for build and another one is for serve, so probably you need to set those as per requirements
– Pardeep Jain
Nov 14 '18 at 10:19
Not tried yet, but there are two options one is for build and another one is for serve, so probably you need to set those as per requirements
– Pardeep Jain
Nov 14 '18 at 10:19
that sounds interesting! How do I set options for build and serve?
– Tobias Gassmann
Nov 14 '18 at 10:20
that sounds interesting! How do I set options for build and serve?
– Tobias Gassmann
Nov 14 '18 at 10:20
add a comment |
2 Answers
2
active
oldest
votes
Inside your angular.json there is a configurations object projects.project-name.architect.build.configurations.
Set the assets inside the prod entry to
"prod":
//...
"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.
But assets will be available forserveonly?
– Pardeep Jain
Nov 14 '18 at 13:32
when using prod it says: "Configuration 'production' could not be found in project", I could solve this by renaming "prod" to "production"
– Tobias Gassmann
Nov 14 '18 at 13:34
1
it depends on how you named the configuration, but the default is prod :) that's why I reverted it
– PierreDuc
Nov 14 '18 at 13:35
architect->build->options->assets: ["my-dev-only-asset.css"] will be available for serve
– Tobias Gassmann
Nov 14 '18 at 13:36
add a comment |
PS: Code not tried yet but for comment its getting too long so posting as answer here.
"architect":
"build":
"builder": "@angular-devkit/build-angular:browser",
"options":
....
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
...
],
"scripts":
,
"serve":
"assets": [
"src/assets"
],
1
I tried this approach also, as it seems "assets" is not allowed under "serve". But thank you for you help! :-)
– Tobias Gassmann
Nov 14 '18 at 13:04
@TobiasGassmann your welcome, but accepted answer is not similer to mine somewhere?
– Pardeep Jain
Nov 14 '18 at 13:33
yes it is :-) but the SO-System allows me to accept one answer only... hmm...
– Tobias Gassmann
Nov 14 '18 at 13:39
Haha, my bad luck :P Anyways thanks for your comment on accepted answer, now got something new :)
– Pardeep Jain
Nov 14 '18 at 13:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297722%2fexclude-assets-in-production-build%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Inside your angular.json there is a configurations object projects.project-name.architect.build.configurations.
Set the assets inside the prod entry to
"prod":
//...
"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.
But assets will be available forserveonly?
– Pardeep Jain
Nov 14 '18 at 13:32
when using prod it says: "Configuration 'production' could not be found in project", I could solve this by renaming "prod" to "production"
– Tobias Gassmann
Nov 14 '18 at 13:34
1
it depends on how you named the configuration, but the default is prod :) that's why I reverted it
– PierreDuc
Nov 14 '18 at 13:35
architect->build->options->assets: ["my-dev-only-asset.css"] will be available for serve
– Tobias Gassmann
Nov 14 '18 at 13:36
add a comment |
Inside your angular.json there is a configurations object projects.project-name.architect.build.configurations.
Set the assets inside the prod entry to
"prod":
//...
"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.
But assets will be available forserveonly?
– Pardeep Jain
Nov 14 '18 at 13:32
when using prod it says: "Configuration 'production' could not be found in project", I could solve this by renaming "prod" to "production"
– Tobias Gassmann
Nov 14 '18 at 13:34
1
it depends on how you named the configuration, but the default is prod :) that's why I reverted it
– PierreDuc
Nov 14 '18 at 13:35
architect->build->options->assets: ["my-dev-only-asset.css"] will be available for serve
– Tobias Gassmann
Nov 14 '18 at 13:36
add a comment |
Inside your angular.json there is a configurations object projects.project-name.architect.build.configurations.
Set the assets inside the prod entry to
"prod":
//...
"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.
Inside your angular.json there is a configurations object projects.project-name.architect.build.configurations.
Set the assets inside the prod entry to
"prod":
//...
"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.
edited Nov 14 '18 at 13:17
answered Nov 14 '18 at 10:23
PierreDucPierreDuc
30.7k56179
30.7k56179
But assets will be available forserveonly?
– Pardeep Jain
Nov 14 '18 at 13:32
when using prod it says: "Configuration 'production' could not be found in project", I could solve this by renaming "prod" to "production"
– Tobias Gassmann
Nov 14 '18 at 13:34
1
it depends on how you named the configuration, but the default is prod :) that's why I reverted it
– PierreDuc
Nov 14 '18 at 13:35
architect->build->options->assets: ["my-dev-only-asset.css"] will be available for serve
– Tobias Gassmann
Nov 14 '18 at 13:36
add a comment |
But assets will be available forserveonly?
– Pardeep Jain
Nov 14 '18 at 13:32
when using prod it says: "Configuration 'production' could not be found in project", I could solve this by renaming "prod" to "production"
– Tobias Gassmann
Nov 14 '18 at 13:34
1
it depends on how you named the configuration, but the default is prod :) that's why I reverted it
– PierreDuc
Nov 14 '18 at 13:35
architect->build->options->assets: ["my-dev-only-asset.css"] will be available for serve
– Tobias Gassmann
Nov 14 '18 at 13:36
But assets will be available for
serve only?– Pardeep Jain
Nov 14 '18 at 13:32
But assets will be available for
serve only?– Pardeep Jain
Nov 14 '18 at 13:32
when using prod it says: "Configuration 'production' could not be found in project", I could solve this by renaming "prod" to "production"
– Tobias Gassmann
Nov 14 '18 at 13:34
when using prod it says: "Configuration 'production' could not be found in project", I could solve this by renaming "prod" to "production"
– Tobias Gassmann
Nov 14 '18 at 13:34
1
1
it depends on how you named the configuration, but the default is prod :) that's why I reverted it
– PierreDuc
Nov 14 '18 at 13:35
it depends on how you named the configuration, but the default is prod :) that's why I reverted it
– PierreDuc
Nov 14 '18 at 13:35
architect->build->options->assets: ["my-dev-only-asset.css"] will be available for serve
– Tobias Gassmann
Nov 14 '18 at 13:36
architect->build->options->assets: ["my-dev-only-asset.css"] will be available for serve
– Tobias Gassmann
Nov 14 '18 at 13:36
add a comment |
PS: Code not tried yet but for comment its getting too long so posting as answer here.
"architect":
"build":
"builder": "@angular-devkit/build-angular:browser",
"options":
....
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
...
],
"scripts":
,
"serve":
"assets": [
"src/assets"
],
1
I tried this approach also, as it seems "assets" is not allowed under "serve". But thank you for you help! :-)
– Tobias Gassmann
Nov 14 '18 at 13:04
@TobiasGassmann your welcome, but accepted answer is not similer to mine somewhere?
– Pardeep Jain
Nov 14 '18 at 13:33
yes it is :-) but the SO-System allows me to accept one answer only... hmm...
– Tobias Gassmann
Nov 14 '18 at 13:39
Haha, my bad luck :P Anyways thanks for your comment on accepted answer, now got something new :)
– Pardeep Jain
Nov 14 '18 at 13:41
add a comment |
PS: Code not tried yet but for comment its getting too long so posting as answer here.
"architect":
"build":
"builder": "@angular-devkit/build-angular:browser",
"options":
....
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
...
],
"scripts":
,
"serve":
"assets": [
"src/assets"
],
1
I tried this approach also, as it seems "assets" is not allowed under "serve". But thank you for you help! :-)
– Tobias Gassmann
Nov 14 '18 at 13:04
@TobiasGassmann your welcome, but accepted answer is not similer to mine somewhere?
– Pardeep Jain
Nov 14 '18 at 13:33
yes it is :-) but the SO-System allows me to accept one answer only... hmm...
– Tobias Gassmann
Nov 14 '18 at 13:39
Haha, my bad luck :P Anyways thanks for your comment on accepted answer, now got something new :)
– Pardeep Jain
Nov 14 '18 at 13:41
add a comment |
PS: Code not tried yet but for comment its getting too long so posting as answer here.
"architect":
"build":
"builder": "@angular-devkit/build-angular:browser",
"options":
....
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
...
],
"scripts":
,
"serve":
"assets": [
"src/assets"
],
PS: Code not tried yet but for comment its getting too long so posting as answer here.
"architect":
"build":
"builder": "@angular-devkit/build-angular:browser",
"options":
....
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
...
],
"scripts":
,
"serve":
"assets": [
"src/assets"
],
answered Nov 14 '18 at 10:50
Pardeep JainPardeep Jain
41.4k17103146
41.4k17103146
1
I tried this approach also, as it seems "assets" is not allowed under "serve". But thank you for you help! :-)
– Tobias Gassmann
Nov 14 '18 at 13:04
@TobiasGassmann your welcome, but accepted answer is not similer to mine somewhere?
– Pardeep Jain
Nov 14 '18 at 13:33
yes it is :-) but the SO-System allows me to accept one answer only... hmm...
– Tobias Gassmann
Nov 14 '18 at 13:39
Haha, my bad luck :P Anyways thanks for your comment on accepted answer, now got something new :)
– Pardeep Jain
Nov 14 '18 at 13:41
add a comment |
1
I tried this approach also, as it seems "assets" is not allowed under "serve". But thank you for you help! :-)
– Tobias Gassmann
Nov 14 '18 at 13:04
@TobiasGassmann your welcome, but accepted answer is not similer to mine somewhere?
– Pardeep Jain
Nov 14 '18 at 13:33
yes it is :-) but the SO-System allows me to accept one answer only... hmm...
– Tobias Gassmann
Nov 14 '18 at 13:39
Haha, my bad luck :P Anyways thanks for your comment on accepted answer, now got something new :)
– Pardeep Jain
Nov 14 '18 at 13:41
1
1
I tried this approach also, as it seems "assets" is not allowed under "serve". But thank you for you help! :-)
– Tobias Gassmann
Nov 14 '18 at 13:04
I tried this approach also, as it seems "assets" is not allowed under "serve". But thank you for you help! :-)
– Tobias Gassmann
Nov 14 '18 at 13:04
@TobiasGassmann your welcome, but accepted answer is not similer to mine somewhere?
– Pardeep Jain
Nov 14 '18 at 13:33
@TobiasGassmann your welcome, but accepted answer is not similer to mine somewhere?
– Pardeep Jain
Nov 14 '18 at 13:33
yes it is :-) but the SO-System allows me to accept one answer only... hmm...
– Tobias Gassmann
Nov 14 '18 at 13:39
yes it is :-) but the SO-System allows me to accept one answer only... hmm...
– Tobias Gassmann
Nov 14 '18 at 13:39
Haha, my bad luck :P Anyways thanks for your comment on accepted answer, now got something new :)
– Pardeep Jain
Nov 14 '18 at 13:41
Haha, my bad luck :P Anyways thanks for your comment on accepted answer, now got something new :)
– Pardeep Jain
Nov 14 '18 at 13:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53297722%2fexclude-assets-in-production-build%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Probably you need to exclude your
assetsfolder from angular.json configuration, Have you removed that?– Pardeep Jain
Nov 14 '18 at 10:17
If I remove it from the angular.json, the files within that asset-folder wont be served by ng serve anymore ( I load them via an ajax-request)
– Tobias Gassmann
Nov 14 '18 at 10:17
Not tried yet, but there are two options one is for build and another one is for serve, so probably you need to set those as per requirements
– Pardeep Jain
Nov 14 '18 at 10:19
that sounds interesting! How do I set options for build and serve?
– Tobias Gassmann
Nov 14 '18 at 10:20