我正在尝试使用单SPA框架的微前端,我跨越了一个角度应用程序,并完成了单个SPA配置。当我试图引导角形应用程序时,我可以看到main.js的文件大小为9 MB,这对于一个组件的简单示例应用程序来说太大了。

angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"app2": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app2",
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"outputPath": "dist/app2",
"index": "src/index.html",
"main": "src/main.single-spa.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": [],
"customWebpackConfig": {
"path": "./extra-webpack.config.js"
}
},
"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"
}
]
}
}
},
"serve": {
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"browserTarget": "app2:build"
},
"configurations": {
"production": {
"browserTarget": "app2:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "app2: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": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"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": "app2:serve"
},
"configurations": {
"production": {
"devServerTarget": "app2:serve:production"
}
}
}
}
}
},
"defaultProject": "app2",
"cli": {
"analytics": false
}
}package.json
{
"name": "app1",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "npm run serve:single-spa",
"build": "npm run build:single-spa",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build:single-spa": "ng build --prod --deploy-url /dist/app1 --output-hashing none",
"serve:single-spa": "ng serve --disable-host-check --port 4203 --deploy-url http://localhost:4203/ --live-reload false"
},
"private": true,
"dependencies": {
"@angular-builders/custom-webpack": "^8",
"@angular/animations": "~9.1.7",
"@angular/common": "~9.1.7",
"@angular/compiler": "~9.1.7",
"@angular/core": "~9.1.7",
"@angular/forms": "~9.1.7",
"@angular/platform-browser": "~9.1.7",
"@angular/platform-browser-dynamic": "~9.1.7",
"@angular/router": "~9.1.7",
"rxjs": "~6.5.5",
"single-spa": "^5.5.0",
"single-spa-angular": "^4.0.1",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.6",
"@angular/cli": "~9.1.6",
"@angular/compiler-cli": "~9.1.7",
"@angular/language-service": "~9.1.7",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.8.3"
}
}extra-webpack-config.js
const singleSpaAngularWebpack = require('single-spa-angular/lib/webpack').default
module.exports = (angularWebpackConfig, options) => {
const singleSpaWebpackConfig = singleSpaAngularWebpack(angularWebpackConfig, options)
// Feel free to modify this webpack config however you'd like to
return singleSpaWebpackConfig
}帮我缩小文件大小,谢谢
发布于 2021-09-22 13:06:40
您应该尝试使用包分析器(如源地图资源管理器)。这会告诉你是什么占据了所有的空间。
安装该软件包:
npm i -g source-map-explorer使用它分析您的应用程序:
ng build --configuration production --sourceMap=true && source-map-explorer dist\\main-*.*.js发布于 2022-04-11 11:21:56
开发包大小不重要,因为在开发时,您需要在本地下载文件。唯一真正重要的是产品的建造。
如果您将off机器开发到远程服务器,则所有这些都丢失了,因此您应该重新考虑有关此情况的策略。
https://stackoverflow.com/questions/69284527
复制相似问题