我有一个微应用元素和一个正常工作的外壳应用程序。但是,我正在尝试构建没有公共库的微应用程序并从全局范围内引用它们。我按照以下教程使用共享库构建角度元素
- ng g ngx-build-plus:externals
- npm run build:externals (ng serve --extra-webpack-config webpack.externals.js --output-hashing none --single-bundle)
文件 webpack.externals.js 定义了以下外部
module.exports = { "externals": { "rxjs": "rxjs", "@angular/core": "ng.core", "@angular/common": "ng.common", "@angular/common/http": "ng.common.http", "@angular/platform-browser": "ng.platformBrowser", "@angular/platform-browser-dynamic": "ng.platformBrowserDynamic", "@angular/compiler": "ng.compiler", "@angular/elements": "ng.elements", // Uncomment and add to scripts in angular.json if needed // "@angular/router": "ng.router", // "@angular/forms": "ng.forms" } }
在 angular.json 中,有以下脚本
"scripts": [
"node_modules/rxjs/bundles/rxjs.umd.js",
"node_modules/@angular/core/bundles/core.umd.js",
"node_modules/@angular/common/bundles/common.umd.js",
"node_modules/@angular/common/bundles/common-http.umd.js",
"node_modules/@angular/compiler/bundles/compiler.umd.js",
"node_modules/@angular/elements/bundles/elements.umd.js",
"node_modules/@angular/platform-browser/bundles/platform-browser.umd.js",
"node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js"
]
但是现在,该元素没有加载到 shell 应用程序中。它说“ Uncaught ReferenceError: ng is not defined at Object.@angular/core”。我对角度很陌生,我在这里错过了一步吗?看起来 angular.json 脚本不起作用,并且元素(微应用)无法引用全局数组