To enable custom webpack configurations, open the angular. json configuration file. Locate the line "builder": "@angular-devkit/build-angular:browser" inside the architect.
The webpack configuration file webpack. config. js is the file that contains all the configuration, plugins, loaders, etc. to build the JavaScript part of the NativeScript application. The file is located at the root of the NativeScript application.
The Angular CLI can create a new Angular project and it will handle the webpack configuration.
The application builder uses the webpack build tool, with default configuration options specified in the workspace configuration file ( angular. json ) or with a named alternative configuration.
There's a nice way to eject webpack.config.js from angular-cli. Just run:
$ ng eject
This will generate webpack.config.js in the root folder of your project, and you're free to configure it the way you want. The downside of this is that build/start scripts in your package.json will be replaced with the new commands and instead of
$ ng serve
you would have to do something like
$ npm run build & npm run start
This method should work in all the recent versions of angular-cli (I personally tried a few, with the oldest being 1.0.0-beta.21, and the latest 1.0.0-beta.32.3)
According to this issue, it was a design decision to not allow users to modify the Webpack configuration to reduce the learning curve.
Considering the number of useful configuration on Webpack, this is a great drawback.
I would not recommend using angular-cli
for production applications, as it is highly opinionated.
With Angular CLI 6 you need to use builders as ng eject is deprecated and will soon be removed in 8.0. That's what it says when I try to do an ng eject
You can use angular-builders package (https://github.com/meltedspark/angular-builders) to provide your custom webpack config.
I have tried to summarize all in a single blog post on my blog - How to customize build configuration with custom webpack config in Angular CLI 6
but essentially you add following dependencies -
"devDependencies": {
"@angular-builders/custom-webpack": "^7.0.0",
"@angular-builders/dev-server": "^7.0.0",
"@angular-devkit/build-angular": "~0.11.0",
In angular.json make following changes -
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {"path": "./custom-webpack.config.js"},
Notice change in builder and new option customWebpackConfig. Also change
"serve": {
"builder": "@angular-builders/dev-server:generic",
Notice the change in builder again for serve target. Post these changes you can create a file called custom-webpack.config.js in your same root directory and add your webpack config there.
However, unlike ng eject configuration provided here will be merged with default config so just add stuff you want to edit/add.
The CLI's webpack config can now be ejected. Check Anton Nikiforov's answer.
You can hack the config template in angular-cli/addon/ng2/models
. There's no official way to modify the webpack config as of now.
There's a closed "wont-fix" issue on github about this: https://github.com/angular/angular-cli/issues/1656
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