我一直在使用声明文件将模块构建到单个outFile中:
{
"compilerOptions": {
"module": "amd",
"target": "es5",
"declaration": true,
"noImplicitAny": false,
"outFile": "built/index.js",
"sourceMap": true
},
"exclude": [
"bower_components",
"built"
]
}
设置依赖项目时,我可以通过凉亭和打字机导入:
>bower install git://github.com/ca0v/ol3-symbolizer.git#v3.20.1 --save
>typings install ol3-symbolizer=github:ca0v/ol3-symbolizer/built/index.d.ts#v3.20.1 --save --global
并在AMD" dep"中列出依赖关系。阵列:
deps: [
"https://rawgit.com/ca0v/ol3-symbolizer/v3.20.1/built/index.js",
"https://rawgit.com/ca0v/ol3-layerswitcher/v3.20.1/built/index.js",
"https://rawgit.com/ca0v/ol3-popup/v3.20.1/built/index.js",
"built/index"
],
我宁愿不使用添加deps
也不要使用typings
,而是引用依赖项:
import Symbolizer = require("../../bower_components/ol3-symbolizer/format/ags-symbolizer");
当没有嵌套依赖项时,这可以正常工作。但在这种情况下,ol3-symbolizer也对ol3-popup有一个bower依赖。使用bower
安装ol3-symbolizer
也会安装ol3-popup
,但会缩小文件结构和引用中断:
import { Popup } from "../bower_components/ol3-popup/src/ol3-popup";
需要修复并成为:
import { Popup } from "../../ol3-popup/src/ol3-popup";
有没有办法以避免破坏这些路径的方式组织这些项目?
答案 0 :(得分:0)
解决方案是使用tsconfig.json添加路径:
{
"compilerOptions": {
"removeComments": true,
"declaration": false,
"module": "amd",
"target": "es3",
"noImplicitAny": true,
"sourceMap": true,
"outFile": "./built/index.js",
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"ol3-layerswitcher/*": [
"./bower_components/ol3-layerswitcher/ol3-layerswitcher/*"
],
"ol3-symbolizer/*": [
"./bower_components/ol3-symbolizer/ol3-symbolizer/*"
],
"ol3-popup/*": [
"./bower_components/ol3-popup/ol3-popup/*"
]
}
},
"exclude": [
"bower_components",
"built",
"ol3-lab/tests/data/routes",
"ol3-lab/tests/routing.ts"
]
}
通过此更改,对bower依赖项的所有引用都可以是代码,就好像它们位于根目录中一样,结果是所有依赖项都合并到一个输出文件中。