angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng build - Add option to save bundled js files in different directory and index in different directory

Open naveedahmed1 opened this issue 10 years ago • 26 comments

Here is a feature request.

When we build a project using ng build command, it creates a folder dist and place all bundles and index file in it. I know that we can specify the outdir in angular-cli.json and cli will generate all bundles and index.html file in the specified folder.

What if there is a need to put the bundled js files in a separate directory and index file in separate directory e.g

bundled js in /dist/js/ folder

and index file in /dist/ folder

I tried, copying the generated js bundles to the dist/js folder and updated the paths in index file but it didn't work and console shows 404 error for bundles.

It would be good to add an option to specify path for the bundled js files and index file.

naveedahmed1 avatar Oct 13 '16 19:10 naveedahmed1

+1 for this

paulwscom avatar Jun 14 '19 04:06 paulwscom

Is there a way to split my chunk files in n different folders project wise?? I have multiple projects in single directory. After ng build I get 15 chunks. 5 belongs to each project. I want them to be in serparate folder in the name of the project. Is there a configuration that we can do in angular.json or using webpack and achieve this?? Please comment.

This will be very helpful if we have multiple projects in a single directory and we want to deploy only the specific project chunk files in the server.

Pradeep-nomad avatar Aug 14 '19 13:08 Pradeep-nomad

Here is how I do that : in the file package.json, below the scripts node, I add a script called postbuild that will :

  1. Move the files in the dedicated folder (resources in my example)
  2. Search and replace <script src="*.js"></script> in index.html by <script src="resources/*.js"></script>. The search and replace is done with sed commande line (please be aware that there are some difference with sed commande line on linux or MacOS).

Here is the final look of my package.json file :

{
  "name": "my-project",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json",
    "build": "ng build",
    "postbuild": "mv ./dist/my-project/*.js ./dist/my-project/*.js.map ./dist/my-project/resources; sed -i -e 's/src=\"/src=\"resources\\//g' dist/my-project/index.html",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }
}

moussa-b avatar Aug 21 '19 08:08 moussa-b

+1 for this. We need to be able to have Index.html in the root and scripts in a separate folder. One common case for this is when we integrate an angular application into a another web project, and that other web demands that the js files are stored in a separate folder.

popsovy avatar Aug 26 '19 22:08 popsovy

@moussa-b 2. just put "deployUrl" in your angular.json

This work for me. Thanks

ilpredo avatar Sep 13 '19 12:09 ilpredo

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.