1

In angular 5 , install package or lib required npm install. I'd like to know if it is possible to include library like this :

<script src="http://xxxx/.js" ><script>

or use angular-cli

enter image description hereenter image description here

I don't know which file i should put in the new project .Or how to use it for example :

In angularjs 1.x we could use the script xxx for us to include 3rd party lib, i'd like to do is the same doing the 3rd party lib without using npm install.That's all.It better using below example

````

```

4

2 回答 2

0

要使脚本通过 npm 机制可用,您可以简单地将其替换为 git url 而不是包名,例如 git@bitbucket.com:name/package。

来自npm 文档

<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]

或者,您可以使用 npm 链接的组合,但您仅限于单个系统。

最后,Typescript 本身可以帮助你。假设您的应用程序位于src/app文件夹中,您的库位于src/lib. 您可以简单地使用常规打字稿(或 ES)导入在代码中导入库。Angular 应该负责其余的工作。

于 2018-01-21T12:35:55.527 回答
0

pathstsconfig.json文件中使用库和应用程序作为同一个 Angular 工作区(同一个node_modules文件夹)的一部分。但对我来说,当我在不同的项目(Angular 工作区)中使用它时它不起作用,可能是因为不同版本的 Angular 依赖项。ng serve说: error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'

更新

终于意识到了!可以npm link用来创建指向库的符号链接,并在angular.json文件内部将属性设置preserveSymlinkstrue. 例子:

"architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { ... "preserveSymlinks": true, ...

于 2018-07-12T09:56:24.597 回答