This repository has been archived by the owner on Apr 17, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d501734
commit 8b6305a
Showing
1 changed file
with
18 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
# AngularSvgSpriteLoaderBug | ||
# angular-svg-sprite-issue | ||
|
||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.3.17. | ||
This project reproduces a bug with [svg-sprite-loader](https://github.com/kisenka/svg-sprite-loader) in extract mode when integrating with [Angular CLI](https://github.com/angular/angular-cli). | ||
|
||
## Development server | ||
## Background to the integration | ||
|
||
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. | ||
Angular CLI uses internally [webpack](https://github.com/webpack/webpack) to build an Angular app and handles in general the whole webpack configuration for you. But it also provides an extension point - called [Builders](https://angular.io/guide/cli-builder). With the builder [@angular-builders/custom-webpack](https://www.npmjs.com/package/@angular-builders/custom-webpack) you get access to the webpack configuration that was created by Angular CLI and you can adjust it to your needs. At this point you can integrate the svg-sprite-loader how it is shown by this minimal repository. | ||
|
||
## Code scaffolding | ||
## The issue | ||
|
||
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. | ||
In development everthing works as expected, but when you build for production the following error is thrown: | ||
``` | ||
angular-svg-sprite-issue\node_modules\@angular-devkit\build-webpack\src\utils.js:17 | ||
id: chunk.id.toString(), | ||
^ | ||
## Build | ||
TypeError: Cannot read property 'toString' of null | ||
``` | ||
Although the error is thrown in the package [@angular-devkit/build-webpack](https://www.npmjs.com/package/@angular-devkit/build-webpack) the root cause lies in the plug-in of svg-sprite-loader. In the plug-in a new chunk for the SVG sprite is added to the webpack compilation without setting its `id` ([see code](https://github.com/kisenka/svg-sprite-loader/blob/85f07caed508403ab259b5b13eabc97704e0261b/lib/plugin.js#L165-L179)). | ||
|
||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. | ||
## Reproduction steps | ||
|
||
## Running unit tests | ||
1. `npm install` | ||
2. `npm run build` | ||
|
||
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). | ||
## Debugging with VS Code | ||
|
||
## Running end-to-end tests | ||
|
||
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). | ||
|
||
## Further help | ||
|
||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). | ||
In the repository a debug configuration "ng build --prod" is included to debug the compilation process with VS Code. |