sách gpt4 ai đã đi

Angular như một Webpack bên ngoài

In lại 作者:行者123 更新时间:2023-12-03 16:36:36 34 4
mua khóa gpt4 Nike

我目前正在尝试通过 Webpack 外部对象外部化 Angular 依赖项来缩短构建时间。到目前为止,我已经为 React 和其他小库实现了这一目标。

如果我只是移动 '@angular/compiler' 它也可以工作,但是当外部化 '@angular/core' 和其他人时,我会收到 Can't resolve all parameters for ApplicationModule: (?) at at syntaxError (util.ts:100) at CompileMetadataResolver._getDependenciesMetadata (metadata_resolver.ts:957) ...引导应用程序时出错。

我使用的文件是您可以在 unpkg.com 中找到的 8.2.14 UMD 包,我的外部文件是:

[
/^@example\,
/^rxjs$/,
/^rxjs\/operators$/,
/^@angular\/core$/,
/^@angular\/compiler$/,
/^@angular\/common$/,
/^@angular\/common\/http$/,
/^@angular\/forms$/,
/^@angular\/platform-browser$/,
/^@angular\/platform-browser-dynamic$/,
/^@angular\/router$/,
/^zone\.js$/,
/^single-spa$/
]

rxjs 包是在这里找到的 https://cdn.jsdelivr.net/npm/@esm-bundle .

您可以在此 repo 上看到错误: https://github.com/OriolInvernonLlaneza/test-share-angular

Cảm ơn trước nhé!

编辑:多亏了 yurzui 的回答,这个错误得到了解决。但是,我现在收到另一个错误:
Class constructor I cannot be invoked without 'new'
at new EventEmitter (event_emitter.ts:78)
at new NgZone (ng_zone.ts:97)
at getNgZone (application_ref.ts:358)
at PlatformRef.bootstrapModuleFactory (application_ref.ts:255)
at application_ref.ts:308

1 Câu trả lời

您需要包含 core-js shim 库,以便 Angular 代码可以使用 Reflect.getOwnMetadata从装饰类中读取元数据的方法

index.ejs

<% if (isLocal) { %>
<== add this

Angular CLI 默认在 polyfills.ts 中添加了这个 polyfill对于 jit。但是 single-spa-angular删除这个 polyfill。

请注意,您还应该将 zone.js 包含到您的文件中,以便完整的代码看起来像

index.ejs



làm mới

sai lầm Class constructor I cannot be invoked without 'new'来自 rxjs 包( @esm-bundle/rxjs@6.5.4/system/rxjs.min.js ),这意味着这个包没有正确构建以在浏览器中使用它(更多关于这个错误的信息在这里 Javascript ES6 TypeError: Class constructor Client cannot be invoked without 'new' ).

您可以将 umd 包用于 rxjs
"rxjs": "../../../npm/rxjs@6.5.4/bundles/rxjs.umd.min.js",
"rxjs/operators": "../../../npm/@esm-bundle/rxjs@6.5.4/system/rxjs-operators.min.js",

我会分享整个 inject.ejs下面的文件


<đầu>



Root Config

<% if (isLocal) { %>


<% } %>










System.import("@example/root-config");




关于Angular 作为 Webpack 外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60505372/

34 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com