I'm working on ng2 application and I use @angular/cli
to build it. As output it emits several js files like .inline.js
, .vendor.js
etc.
The question is -- how to set up angular-cli to emit only one file as a result, i.e. bundle vendor.js
, inline.js
etc. into one big file?
I understand that it could be done by using additional bundler but it would be nice to achieve it via ng-cli
PS I don't use lazy loading in this app and definitely won't.
PPS Just concat files afterwards is not an option because:
As for now it looks like moving to pure webpack would be the easiest and best option
UPDATE
there is possibility to avoid vendor.js
setting --vendor-chunk
to true
but as a result I still get several files: inline.bundle.js
main.bundle.js
polyfills.bundle.js
ng buildlink. Compiles an Angular application or library into an output directory named dist/ at the given output path.
The ng build command is intentionally for building the apps and deploying the build artifacts. The command does not generate an output folder. The output folder is – dist/. The ng serve builds artifacts from memory instead for a faster development experience.
--output-hashing all — hash contents of the generated files and append hash to the file name to facilitate browser cache busting (any change to file content will result in different hash and hence browser is forced to load a new version of the file)
src folder: This is the folder which contains the main code files related to your angular application. app folder: The app folder contains the files, you have created for app components. app.
Angular CLI natively doesn't support this.
There are other solutions, including further processing with other tooling after Angular CLI finishes doing its thing, but this will hinder or remove the debugging capabilities Angular provides out-of-the-box.
As the ng eject
command is also being deprecated, the option to reconfigure webpack is not as attractive as it used to be. However, that is still technically a possibility.
The best solution I have found is the ngx-build-plus
plugin, which can be found at https://github.com/manfredsteyer/ngx-build-plus or added to a project via the ng add ngx-build-plus
Angular-CLI command currently. Once installed, it provides additional configuration options for building, including the --single-bundle true
flag that can be added to an ng build
or ng serve
command.
With that flag, a main.js file and a main.js.map file are created, already referenced in the HTML, and it'll just run like that properly out of the box, with full source mapping and debugging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With