我正在使用 custom webpack 与 Angular 8 一起使用 webpack,并希望使用url-loader实现SVG内联,因为应用程序部署到的服务器不支持SVG image/svg+xml mimetype(我不能更改它以支持它)。但是,在构建应用程序时,SVG并没有被内联。
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'
}
]
}
]
}
};
我也尝试过 svg-url-loader 和 svg-inline-loader 库,但我无法内联 SVG。我不知道还有什么可以尝试的。我的配置有问题吗,还是 Angular 做了我没有预料到的事情?