I'm using custom webpack to use webpack with Angular 8, and I want to use url-loader to inline SVGs, because the server the app is being deployed to doesn't support the SVG image/svg+xml mimetype (and I can't change that to support it). However when I build the app, the SVGs aren't being inlined.
Angular.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"Emergent-Event": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "less"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./extra-webpack.config.js"
},
"outputPath": "dist/Emergent-Event",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
...
],
"styles": [
...
],
"scripts": [
...
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"browserTarget": "Emergent-Event:build"
},
"configurations": {
"production": {
"browserTarget": "Emergent-Event:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "Emergent-Event:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
...
],
"styles": [
...
],
"scripts": [
...
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "Emergent-Event:serve"
},
"configurations": {
"production": {
"devServerTarget": "Emergent-Event:serve:production"
}
}
}
}
}},
"defaultProject": "Emergent-Event"
}
extra-webpack.config.js:
module.exports = {
module: {
rules: [
{
test: /\.(svg)$/i,
use: [
{
loader: 'url-loader'
}
]
}
]
}
};
I also tried svg-url-loader and svg-inline-loader libraries, but I couldn't get any of them to inline SVGs. I don't know what else to try. Is there something wrong with my configuration, or is Angular doing something I'm not expecting?
By default angular handles it with file-loader.
Example code how to replace file-loader to base64-inline-loader:
Or you can write code to remove only
svgfromtestfield and add new rule only for it.