繁体   English   中英

Angular 12 加载外部脚本作为类型模块

[英]Angular 12 load external scripts as type module

是否可以将 Angular 设置为加载在architect/build/options/scripts下的angular.json定义的外部architect/build/options/scriptstype="module"

运行 Angular 时,我可以看到自动注入的脚本标签,如下所示:

<script src="runtime.js" type="module"></script>
<script src="polyfills.js" type="module"></script>
<script src="styles.js" type="module"></script>
<script src="scripts.js" defer></script>
<script src="vendor.js" type="module"></script>
<script src="main.js" type="module"></script>

scripts.js有一个 defer 属性,但没有type="module" 我正在尝试将通过 npm 安装的 Stencil JS Web 组件加载到我的应用程序中。 模板组件脚本需要作为模块加载,否则其他导入将不起作用。

我还可以确认目前无法向scripts字段添加type属性。 可能的值是: object 与inject|lazy|bundleName|input属性或直接一个string

要使用角一个WebComponent的,我最终加入import语句到polyfills.ts文件

import 'node_modules/my-web-components/dist/example.js';

我能够看到正确导入的内容,并且我的 web 组件在我的 angular 组件 html 文件中处于活动状态。 此处添加内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM