我对Angular2和WebPack完全陌生,并且很可能非常简单。将库导入到没有NPM的Angular2/WebPack项目中
我们正在尝试将yFiles for HTML合并到Agular2/WebPack项目中。我找到并在NPM上导入了类型文件@types/yfiles
。库的其余部分只能从供应商处获得,而不能在NPM上获得。这正确编译,但是当我调试项目,控制台报告错误:
EXCEPTION: Uncaught (in promise): Error: Error in ./HomeComponent class HomeComponent - inline template:0:0 caused by: yfiles is not defined
Error: Error in ./HomeComponent class HomeComponent - inline template:0:0 caused by: yfiles is not defined
这不是HomeComponent这么多,因为它引用这是使用的问题DiagramComponent。
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'fs-diagram',
templateUrl: './diagram.component.html',
styleUrls: ['./diagram.component.scss']
})
export class DiagramComponent implements OnInit {
private canvas: yfiles.view.CanvasComponent;
constructor() {
this.canvas = new yfiles.view.CanvasComponent();
}
ngOnInit() { }
}
的文件夹结构如下所示:
> root
> .vscode
> node_modules
▼ src
> app
▼ lib
▼ yfiles
> impl
*.js
yfiles.css
> public
> style
main.ts
polyfill.ts
vendor.ts
npm-shrinkwrap.json
package.json
protractor.conf.js
tsconfig.json
tslint.json
typedoc.json
webpack.config.js
给我的感觉是,即使@types/yfiles/index.d.ts
文件存在,它在寻找在运行时*.js
文件。这是问题吗?如果是这样,我如何将它们导入到项目中?
你尝试将其导入: - 可发现的WebPack 2.x中,这可以利用
webpack.config.js
的resolve.modules
配置来指定? import {Co ...等导致无处看到你在代码中引用yfiles。那么你的代码如何知道在哪里提取它(npm会自动为你做) – zerohero你是否也尝试联系供应商和/或阅读他们拥有的文档? – zerohero
尝试添加仅添加 'import ../ lib/yfiles',因为它似乎是全局的。 –