2

How to configure to create separate folder in "dist" folder for all chunk files in angular2?

I have use ngcli and run project with ng build. It creates "dist" folder. That is good.

This is the basic structure of the project:

basic structure of project

But I want to put all *.chunk.js and *.map files in separate folders in dist. Like

dist/modules/0.chunk.js

dist/modules/0.map

So the structure will look like...

enter image description here

2
  • this question might be too broad to answer. there are many ways to do this. Commented Feb 13, 2017 at 5:27
  • Pixelbits Can you please help me with any one way ? Commented Feb 13, 2017 at 7:48

3 Answers 3

1

Although this question is a little bit outdated, I stumbled with the same issue in Angular CLI 7 and 8.

According to Angular documentation you could use '--resourceOutputPath' and '--deployUrl'. Unfortunately --resourceOutputPath only works for assets defined in stylesheet and '--deployUrl' doesn't put the assets in a folder.

My current solution is:

  1. set the 'baseHref' option in the build config to '/static-files/'
  2. copy the index.html file from the output folder and put it 1 folder up.

Now you end with a structure like

/dist
   index.html
   /static-files
      chunk1.js
      chunk2.js
      etc

Of course now all your assets are in a separate folder and not only your js files. But it works for me.

Note: when you also using the Angular Routing, you need to set the 'APP_BASE_HREF' manual because otherwise the router is looking for 'staric-files' in your url (https://angular.io/api/common/APP_BASE_HREF)

Sign up to request clarification or add additional context in comments.

Comments

0

You can use Angular ClI, then create multiple NgModules, and use Lazyload in the Router. Then, when you build ng build --prod, each module will be in a separate file.

Below are a couple of recommended articles regarding lazyload: http://blog.angular-university.io/angular2-ngmodule/ https://angular-2-training-book.rangle.io/handout/modules/lazy-loading-module.html

1 Comment

Thanks Tuong Le. But I have put *.chunk.js and *.map file in dist/modules folder. I hope you got it.
0

Try using a separate build package like gup or grunt, that will make the chunk files sent to a separate folder. or otherwise you can also create a Compiler option{ outDir: 'src/chunk'} in tsconfig.json. See if this solves your issue.

1 Comment

Please be more specific on how it should implement what you are suggesting. Just to ask the OP to try to build a whole new build pipe using Gulp or Grunt with the hope that maybe this will solve the issue is not very helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.