2016-08-01 35 views
0

我有两个使用webpack作为模块打包器和打字稿的Angular2项目。了解Angular 2 webpack项目中的源代码符号链接

为了共享代码,我拆分了一些源代码,并为这两个项目中的每一个的这个“外部”源代码创建了一个符号链接。

完成此操作后,“符号链接代码”无法正确解析导入

低于“hello world”项目以显示我的顾虑。

https://github.com/datracka/angular2-symlink-issue

该项目运行直线前进,但如果你删除给​​定src文件夹,并创建一个符号链接到具有相同的源代码中的另一个src文件夹,但位于/another/path/src,那么你得到一个编译错误:

ERROR in .-shared/src/main.ts 
Module build failed: TypeError: Path must be a string. Received undefined 
    at assertPath (path.js:7:11) 
    at Object.dirname (path.js:1326:5) 
    at ensureTypeScriptInstance (/Users/vicensfayos/Projects/angular2-whatafuck/node_modules/ts-loader/index.js:156:103) 
    at Object.loader (/Users/vicensfayos/Projects/angular2-whatafuck/node_modules/ts-loader/index.js:403:14) 

所以我的问题是:当我将源代码“分发”到项目文件夹本身的另一个文件夹中时,我缺少符号链接?

我的猜测是关于在webpack​​中配置正确解析对象以覆盖node.js加载node_modules算法https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders但不是运气。

希望有人能指出我的方向。

回答

1

我找到了答案。

我的猜测是对的。它关于nodejs如何解决依赖关系。 https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders

符号链接代码试图找到依赖性,一直向上移动,直到找到node_module。但没有什么。 node_module位于父项目中。

因此,解决方案是从符号链接代码创建另一个符号链接到父项目的node_modules文件夹以解决依赖关系。