我的结构(经修订)如下:
workspace
|- thegame
|- node_modules
| package.json
| bs-config.json
|- src
| tsconfig.json
|- app
| game.model.ts (<-- here I would like to import game-engine)
|- game-engine
|- dist (after the local build)
| package.json
| tsconfig.json
|- lib
| index.ts (the actual engine module)我在“游戏”路径中运行"npm“的应用程序(Angular2)。
我应该在游戏/src/tsconfig.json中添加什么,这样我就可以在game.model.ts中执行以下操作了?
import { Engine } from 'game-engine';我曾尝试将“游戏引擎”与“游戏/节点_模块”链接起来,但当我使用lightserve运行该项目时,它会给出"404 GET /游戏引擎“。
我想开发与web应用程序分离的引擎。我还对如何实现这一目标的任何其他提示感兴趣。
该项目基于https://github.com/angular/quickstart的Range2Quickstart
发布于 2017-07-20 11:55:06
由于您正在使用一个使用SystemJS和NPM作为基础的角快速启动工具包,并且考虑到您如何描述您的目录布局,您将需要采取以下步骤。
在workspace/thegame中打开终端并运行
npm install --save ../game-engine这将告诉npm从磁盘上的那个位置安装包,作为thegame应用程序的标准依赖项。
现在,我们只需要告诉SystemJS新添加的依赖项位于何处。SystemJS使用显式配置(相对于递归目录遍历)来定位依赖项。这是一件好事,但是由于我们使用的是NPM而不是像JSPM这样的东西,所以我们需要手动设置它。
幸运的是,它相当于添加到systemjs.config.js文件中的一行,根据快速启动,该行应该位于thegame目录的src子目录中。
将以下内容添加到配置对象的"map"属性中:
"game-engine": "npm:game-engine/dist/index.js"最终,该文件将看起来像
SystemJS.config({
paths: {
"npm:": "node_modules/"
},
map: {
"game-engine": "npm:game-engine/dist/index.js",
"@angular/core": "npm:@angular/core/bundles/core.umd.js",
// etc.
}
// etc.
});https://stackoverflow.com/questions/45212923
复制相似问题