某些文件夹中的TypeScript tsconfig输出文件 [英] TypeScript tsconfig Output files in certain folders
问题描述
我正在尝试拥有3个文件夹(ts,js,map)... 1个用于TS,1个用于编译的js,1个用于地图文件.这不可能吗?我在这里看到了几个问题,但没有找到答案.我正在使用Webstorm,Npm,并通过 Angular2示例运行.我将ts文件放在一个文件夹中,并将所有输出放在另一个文件夹中,但是无法将地图放入它自己的文件夹中.最坏的情况下,至少我可以将地图合并为一个文件.我已经尝试inlineSourceMap
,inlineSources
,sourceRoot
和mapRoot
=全部失败.
I am trying to have 3 folders (ts,js,map)... 1 for TS, 1 for compiled js, and 1 for the map files. Is this not possible? I have seen a couple of questions on here, but didn't find the answer. I am using Webstorm, Npm, and running through the Angular2 example. I have the ts file in one folder and all the output in another, but can't get the map to go into it's own. Worst case senior at least can I get the maps to be one file. I've tried inlineSourceMap
, inlineSources
, sourceRoot
, and mapRoot
= all failed.
tsconfig.json(链接到模式):
tsconfig.json (link to schema):
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors":true,
"sourceMap": true,
------ Tried a combination of...
"inlineSourceMap": true,
"inlineSources": true,
"mapRoot": "app/map",
"sourceRoot": "app/map",
------
"outDir": "app/js"
},
"exclude": [
"node_modules",
"bower_components"
]
package.json
package.json
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
},
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.2",
"systemjs": "0.19.6",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"zone.js": "0.5.10"
},
"devDependencies": {
"concurrently": "^1.0.0",
"lite-server": "^1.3.4",
"typescript": "^1.7.5"
},
"main": "",
"author": "",
"description": ""
}
推荐答案
您处在正确的轨道上.使用tsconfig.json中的"outDir"
设置要让transpiled.js移出的位置,然后使用gulp,grunt或custom之类的任务-将map.js文件复制到所需位置
You are on the right track. Use the "outDir"
in your tsconfig.json to set the out location of you want the transpiled.js to go, then use a task such as a gulp, grunt or custom -- to copy the map.js files to the desired location.
sourceRoot
和sourceMap
不会执行您认为的操作.它们仅允许您在sourceMap中指定路径,浏览器应该在该路径中找到地图和源ts.它们不会更改输出的位置.
The sourceRoot
and sourceMap
don't do what you think they do. They just allow you to specify a path within the sourceMap where your browser should expect to find the map and source ts. They don't alter where they are output.
示例gulpfile.js
example gulpfile.js
var gulp = require('gulp');
var del = require('del');
gulp.task('move' => () {
gulp.src(['app/js/**/*.map.js'])
.pipe(del())
.pile(dest('app/map'))
})
类似的事情应该起作用.
Something like that should work.
这篇关于某些文件夹中的TypeScript tsconfig输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!