简体   繁体   English

什么是将节点模块导入角型脚本/ angularcli的正确方法

[英]what is the right way to import a node module to angular typescript / angularcli

im importing some "legacy" (non typescript) js libs to my angular SPA. 我将一些“传统”(非打字稿)js库导入我的角度SPA。

normally I just add a load from the cdn to index.html like: 通常我只是将CDN的负载添加到index.html中,例如:

<script src="//cdnjs.cloudflare.com/ajax/libs/pako/1.0.6/pako.min.js"></script>

and in the angular-component i just decale 而在角度分量中,我只是降低了

declare var pako: any;

this typically works. 这通常有效。 Now i like to "host" this lib locally. 现在,我想在本地“托管”此库。 I can add it to the angular project with 我可以将其添加到角度项目

npm install pako

But how do I add it than to the angular app ? 但是,我如何将其添加到有角度的应用程序呢?
I tested adding an import to polyfills.ts (this works for hammerjs but not for pako) 我测试了将导入添加到polyfills.ts(这适用于Hammerjs但不适用于pako)

Also this should work for ng build (and than probably get added to the compiled / packed runtime.js 这也应该适用于ng build(并且可能会添加到已编译/打包的runtime.js中

BTW: here is a test stackblitz https://stackblitz.com/edit/ng-load-pako 顺便说一句:这是一个测试stackblitz https://stackblitz.com/edit/ng-load-pako

I love all the questions that provide a stackblitz link so that I can easily provide the correct answer: 我喜欢所有提供stackblitz链接的问题,因此我可以轻松提供正确的答案:

https://stackblitz.com/edit/ng-load-pako-gfunsb https://stackblitz.com/edit/ng-load-pako-gfunsb

Basically, you just need to do: 基本上,您只需要执行以下操作:

import * as pako from 'pako';

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

相关问题 AngularCli将节点模块导入到角度app.module loadChildren - AngularCli Import node module to angular app.module loadChildren 用Angular中的TypeScript筛选数组的正确方法是什么? - What is the right way to filter an array with TypeScript in Angular? 无论我尝试什么,都无法在 Angular Typescript 模块中导入 Node、JS 或 Electron 库 - Cannot import Node, JS, or Electron library in Angular Typescript module no matter what I try Angular2(Typescript)无法从@types导入节点模块 - Angular2 (Typescript) can't import node module from @types 在Angular2(AngularCLI)中未找到模块elasticsearch - Module elasticsearch not found within Angular2 (AngularCLI) 如何在Angular中导入节点模块? - How to import node module in Angular? 有没有办法使用与“路径”属性相同的样式的 typescript 配置文件从节点模块抽象导入? - Is there a way to abstract the import from a node module using typescript config files in the same style as the 'paths' property? Angular模块导入的范围是什么 - What is the scope of an Angular module Import 从 angular 中的子节点路由到另一个根节点的正确方法是什么? - What is the right way to route to another root node from a child node in angular? 通过键入在Angular 2中简单导入节点模块 - Simple Import of Node Module in Angular 2 with Typings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM