ng build - Add option to save bundled js files in different directory and index in different directory
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.
Dupe of https://github.com/angular/angular-cli/issues/2276
Its not duplicate of #2276 , but valid question. I also need to separate built index.html and all js files in separate folder.
The --deploy-url flag (that does what --public-path does for webpack) has been around for a while: https://github.com/angular/angular-cli/wiki/build
+1 Any update on this ? I am facing a similar issue.
There is still no solution to this that I've found.. why is this closed? --deploy-url and --base-href correctly set values in index.html. Neither of these address the problem of wanting to put index.html in one folder and all the bundled .js files in another. What is the solution?
@filipesilva if you're looking for a duplicate of this, then try this one: https://github.com/angular/angular-cli/issues/2951
I'm not sure if the duplicate you've assigned is an actual duplicate. It seems different.
On this ticket: I am disappointed in the fact that Angular-CLI is taking away useful options that webpack had already provided. (Especially given the fact that Vue-CLI provides just that kind of functionality)
We here at the company are migrating away from some old structures but we cannot move all at once.
So for the next year or 2 we will be having a scenario that requires the index-file to sit in a folder location that is not a child of the dist-folder but more like the great-uncles neighbors friend-who-he-met-at-a-bars sibling nth-removeds dogs hairstylist.
So: "(How) can i make index end up in that separate folder?" is a vital question for our efforts to ditch the old crap in favor of angular.
I find it hard to imagine we are the only company that made a too-quick choice of how to deliver frontends. Migrating from these mistakes to Angular will usually be a stepwise process. Being able to support this process should be rather beneficial to Angular and Webdevelopment in general.
@filipesilva This is exactly what I am trying to do: " 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 "
Currently I only found out that I can use ng build --deploy-url "js/" to update the location of the js files in the index.html, but the .js files are still being output in the dist folder when I want them to be output in the dist/js/ folder.
I want to do this since I was explained that our current server setup has some request limits for prefixes. Prefixes = folders. So if I keep many files in one folder. That limit is hit very fast. So I want to move the .js files in our project in another folder.
2 years later I find I still have to do it with a build script...? I could not find an option in angular.json to change the .js bundles output location. Did I miss something? Or what is the progress with this?
Thank you.
Why is this ticket closed?! This is a major bug which forces us to use js files in root directory which is not possible in some cases. I can't even imagine that it's not implemented.
--deploy-url is not the solution because dev environment should be equal to prod
Some hack available? I need to have index.html in other folder too and can't get in to working state. :/
+1 for this
+1 we need this feature !
+1 please @filipesilva reopen this issue. We can achieve this goal using native Webpack, so please remove this limit from angular-cli
+1 for this please!!!!!!!
Hello, I'm in need of this too @filipesilva
I'm using the Django web framework, and I need to run some server side logic before I provide the Angular index.html. To do this, I need to store it as a template, which requires putting it in a special folder separate folder from the other css/js files.
The index.html stored as a template connects with the separately stored static css/js files without any effort thanks to --deploy-url.
The directory structure looks something like this:
. // <- project root
├── ...
│
├── foo
│ ├── ...
│ ├── static
│ │ ├── bar // <- css/js files stored in this directory
│ │ │ ├── es2015-polyfills.js
│ │ │ ├── es2015-polyfills.js.map
│ │ │ ├── favicon.ico
│ │ │ ├── main.js
│ │ │ ├── main.js.map
│ │ │ ├── polyfills.js
│ │ │ ├── polyfills.js.map
│ │ │ ├── runtime.js
│ │ │ ├── runtime.js.map
│ │ │ ├── styles.js
│ │ │ ├── styles.js.map
│ │ │ ├── vendor.js
│ │ │ └── vendor.js.map
│ │ ├── ...
│ ├── templates // <- special folder for templates
│ │ ├── ...
│ │ ├── index.html // <- Angular index.html file
│ │ ├── ...
│ ├── ...
│ └── views.py // <- view controllers can only look in templates directory
├── ...
At the moment, I have to build the entire app into static/bar/ and then manually move the index.html to the correct place in templates/.
I need a one-liner than can build the app, put the css/js files in the static/bar/ directory, and the index.html in the templates directory.
Hi All, do we have any update on this? I am having same issue and not being able to fix @filipesilva.
I am having this issue as well. I am trying to separate in a different folder than the root folder the "js" and fonts files.
I found this video https://www.codingforentrepreneurs.com/projects/angular-django/ng-build-django-static that help a little, but I hope someone fix this issue soon
For anyone needs a way to achieve this goal through angular-cli, please have a look here: https://github.com/softdays/angularcli-index-location/commit/c9918fd079ba9518a126735af501ab6de2ac37be
Key steps
npm i -D @angular-builders/custom-webpack- angular.json > projects > your-project-name > architect > build > replace
buildervalue by:"builder": "@angular-builders/custom-webpack:browser"
- angular.json > projects > your-project-name > architect > build > options > outputPath:
- Prepend output path with your subfolder, i.e.
"outputPath": "dist/app"
- Prepend output path with your subfolder, i.e.
- angular.json > projects > your-project-name > architect > build > options, add:
"customWebpackConfig": { "path": "./extra-webpack.config.js", "replaceDuplicatePlugins": true }` - angular.json > projects > your-project-name > architect > build > configurations, add:
"deployUrl": "app/", "baseHref": "", - Create
extra-webpack.config.jsfile at project root with the content below:const fs = require('fs'); module.exports = (config, options) => { config.plugins.push({ apply: (compiler) => { compiler.hooks.afterEmit.tap('MyAfterEmitPlugin', (compilation) => { // Replace 'app' path below with your subfolder path fs.renameSync('./dist/app/index.html', './dist/index.html'); fs.renameSync('./dist/app/favicon.ico', './dist/favicon.ico'); }); } }); return config; };
I'd like to weigh in and ask for this feature as well.
SharePoint (2013) has a hard requirement for placing assets and pages in different directories (libraries). The current angular-cli requirement of index.html being adjacent to other assets works fine for local development purposes but when deploying to production (on a SharePoint farm) it becomes highly problematic - often requiring that paths to assets be rewritten. I suspect that more recent versions of SharePoint still has this requirement.
You also need this feature if you want to use angular with github pages