首页 > 解决方案 > IE 在 webpack $$_lazy_route_resource 期间冻结

问题描述

我有一个使用 ng build 编译的非平凡 Angular 7 Web 应用程序,它在 DEV 模式下约为 4.7meg,分为 6 个块,最大的是供应商在 3.1,其次是主在 1.1。它的生产量约为 3meg。2.3 供应商,0.3 主要

我需要它在 IE 11 中工作。在初始页面加载时,它会冻结大约 15 秒。通过冻结我的意思是我得到蓝色圆圈指示器,如果我点击寡妇,它会变苍白并且(没有响应)出现在标题栏中

使用 IE 性能分析器,我可以看到绝大多数时间(13-14 秒)是 HTML 解析和带有 url 的脚本的脚本评估

webpack:///frontend/$_lazy_route_resource lazy namespace object

其中的内容是

function webpackEmptyAsyncContext(req) {
    // Here Promise.resolve().then() is used instead of new Promise() to prevent
    // uncaught exception popping up in devtools
    return Promise.resolve().then(function() {
        var e = new Error("Cannot find module '" + req + "'");
        e.code = 'MODULE_NOT_FOUND';
        throw e;
    });
}
webpackEmptyAsyncContext.keys = function() { return []; };
webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
module.exports = webpackEmptyAsyncContext;
webpackEmptyAsyncContext.id = "./frontend/$$_lazy_route_resource lazy recursive";

请注意,“前端”是我的应用程序所在的文件夹,我什至没有使用延迟加载。

Chrome 不会死机,加载速度更快,而且似乎根本没有提到这个 url,而是像我预期的那样将大部分时间花在 main.js 中。

我的 angular.json

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "defaultProject": "portal",
    "projects": {
        "portal": {
            "root": "",
            "sourceRoot": "frontend/app-ng",
            "projectType": "application",
            "prefix": "",
            "schematics": {},
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        "outputPath": "frontend/public",
                        "index": "frontend/app-ng/app.html",
                        "main": "frontend/main.ts",
                        "polyfills": "frontend/polyfills.ts",
                        "tsConfig": "frontend/tsconfig.app.json",
                        "assets": [
                            "frontend/app-ng/index.php",
                            "frontend/app-ng/favicon.ico",
                            "frontend/app-ng/env.js"
                        ],
                        "styles": [
                            "frontend/styles.scss"
                        ],
                        "scripts": []
                    },
                    "configurations": {
                        "production": {
                            "fileReplacements": [
                                {
                                    "replace": "frontend/environments/environment.ts",
                                    "with": "frontend/environments/environment.prod.ts"
                                }
                            ],
                            "optimization": true,
                            "outputHashing": "all",
                            "sourceMap": false,
                            "extractCss": true,
                            "namedChunks": true,
                            "aot": true,
                            "extractLicenses": true,
                            "vendorChunk": true,
                            "buildOptimizer": true
                        }
                    }
                },
                "serve": {
                    "builder": "@angular-devkit/build-angular:dev-server",
                    "options": {
                        "browserTarget": "portal:build"
                    },
                    "configurations": {
                        "production": {
                            "browserTarget": "portal:build:production"
                        }
                    }
                },
                "extract-i18n": {
                    "builder": "@angular-devkit/build-angular:extract-i18n",
                    "options": {
                        "browserTarget": "portal:build"
                    }
                },
                "test": {
                    "builder": "@angular-devkit/build-angular:karma",
                    "options": {
                        "main": "frontend/test.ts",
                        "polyfills": "frontend/polyfills.ts",
                        "tsConfig": "frontend/tsconfig.spec.json",
                        "karmaConfig": "frontend/karma.conf.js",
                        "styles": [
                            "frontend/styles.scss"
                        ],
                        "scripts": [],
                        "assets": []
                    }
                },
                "lint": {
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": {
                        "tsConfig": [
                            "frontend/tsconfig.app.json",
                            "frontend/tsconfig.spec.json"
                        ],
                        "exclude": [
                            "**/node_modules/**"
                        ]
                    }
                }
            }
        },
        "portal-e2e": {
            "root": "e2e/",
            "projectType": "application",
            "architect": {
                "e2e": {
                    "builder": "@angular-devkit/build-angular:protractor",
                    "options": {
                        "protractorConfig": "e2e/protractor.conf.js",
                        "devServerTarget": "portal:serve"
                    },
                    "configurations": {
                        "production": {
                            "devServerTarget": "portal:serve:production"
                        }
                    }
                },
                "lint": {
                    "builder": "@angular-devkit/build-angular:tslint",
                    "options": {
                        "tsConfig": "e2e/tsconfig.e2e.json",
                        "exclude": [
                            "**/node_modules/**"
                        ]
                    }
                }
            }
        }
    },
    "schematics": {
        "@schematics/angular:component": {
            "styleext": "scss"
        }
    }
}

我知道 IE 可能会比更现代的浏览器慢,但冻结是糟糕的用户体验和糟糕的第一印象。

更新

在处理一个最小的完整示例时,我发现没有调用,enableProdMode() 所以我修复了这个问题,问题就消失了。所以开发模式代码中似乎有些东西是 IE 不喜欢的?

标签: angularinternet-explorerwebpack

解决方案


推荐阅读