Typescript 导入ng2引导将更改我的tsc输出目录结构
我有以下文件夹结构Typescript 导入ng2引导将更改我的tsc输出目录结构,typescript,angular,tsc,ng2-bootstrap,Typescript,Angular,Tsc,Ng2 Bootstrap,我有以下文件夹结构 dist src module1 m1.ts module2 m2.ts .tsconfig.json ... 我已将tsc配置为输出到dist/js,因此在运行npm run tsc后,我有以下内容: dist js module1 m1.js module2 m2.js src ... 经过多次努力,我终于将ng bootstrap集成到了我的项目中 如果我从我的应用程序中
dist
src
module1
m1.ts
module2
m2.ts
.tsconfig.json
...
我已将tsc
配置为输出到dist/js
,因此在运行npm run tsc
后,我有以下内容:
dist
js
module1
m1.js
module2
m2.js
src
...
经过多次努力,我终于将ng bootstrap
集成到了我的项目中
如果我从我的应用程序中的某个地方导入,例如:
从“ng2引导/components/ACCORDION”导入{ACCORDION_指令}代码>
然后运行npm run tsc
myfolder结构更改为:
dist
js
node_modules
ng2-bootstrap
components
accordian
...
src
module1
m1.js
module2
m2.js
src
....
为什么会这样
我将:
包含在我的index.html
我能用angular2做到这一点
和
从'angular2/core'导入{Component}
这不会创建dist/js/node\u modules/angular2
文件夹
更新
以下是我的tsconfig.json的内容
{
"compilerOptions": {
"target": "ES5",
"outDir": "./dist/js",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"dist",
"typings/main",
"typings/main.d.ts"
]
}
我已经想出了一个解决办法。显然,源.ts
文件与.d.ts
文件位于同一目录中。因此它会编译这些文件。(我在途中的某个地方读到了这篇文章,我不确定其原因/原因)但是,解决方案是删除节点模块/ng2引导中的所有.ts
igoring*.d.ts
文件
我创建了一个节点脚本来执行此操作:
// ./scripts/hack-remove-files.js
var fs = require('fs-extra')
var glob = require("glob");
var options = { ignore: '**/*.d.ts'};
glob("node_modules/ng2-bootstrap/**/*.ts", options, function (er, files) {
for(i in files){
removeFile(files[i]);
}
});
glob("node_modules/ng2-file-upload/**/*.ts", options, function (er, files) {
for(i in files){
removeFile(files[i]);
}
});
removeFile = function(file){
fs.remove(file, function (err) {
if (err) return console.error(err)
})
}
我在npm中以postinstall
脚本的形式运行此脚本:
"scripts": {
...
"postinstall": "typings install && node ./scripts/hack-remove-files.js",
}
下载软件包后,只需执行一次
另一种命令行方法是:
find node_modules/ng2 bootstrap-name'*.ts'| grep-v'\.d\.ts$'| xargs rm
编辑
我发现了最初的问题,其中提到了这一切:你能给我们你的tsconfig.json
?谢谢同样值得一提的是,我在tsconfig.json
中设置了“rootDir”:“/src”
,这在从“ng2引导”导入之前都很好。。“
然后我会得到错误。node_modules/ng2 bootstrap/components/accordion.ts”不在“rootDir”src下。
当运行npm run tsc
时,请参考此repo结构看起来与此repo的结构相同。我有相同的问题。导入ng2引导程序会在my dist文件夹中创建节点_模块,作为src的同级(如果不存在ng2引导程序导入,则编译的内容将直接转到dist)。我悬赏,以引起打字人员的注意。