I am currently writing a side project where I can learn more about TypeScript and ES6 (using babel).
I wanted to use ES6 with my TypeScript, so I settled on the following workflow.
Typescript (ES6) -> Babel (ES6) -> ES5
Now I am using Gulp to automate all of this, and I am having a hard time getting the sourcemaps to generate properly. I should mention that this style was suggested to me by a user on /r/typescript so I am not even sure if it is possible.
Anyways here is my current gulp task
var server = $.typescript.createProject('src/server/tsconfig.json');
gulp.task('build', ['vet'], function () {
var sourceRoot = path.join(__dirname, 'src/server/**/*.ts');
return gulp.src('src/server/**/*.ts')
.pipe($.sourcemaps.init())
.pipe($.typescript(server))
.pipe($.babel())
.pipe($.sourcemaps.write('.', { sourceRoot: sourceRoot}))
.pipe(gulp.dest('build/server'));
});
I have tried many different approaches, but none work. When debugging in VSCode, the entrypoint of my app: build/server/index.js
loads and finds the source file src/server/index.ts
properly.
However when VSCode attempts to step into another file say build/server/utils/logger/index.js
it looks for src/server/utils/logger/index.js
which it doesn't find because it should be looking for a *.ts file.
So what am I doing wrong? Or is this even possible? I've been staring at this for about 5 hours now. So any insight would be great.
Also VSCode 0.9.x displays the '.../.js' file not found
and VSCode 1.0 just fails silently.
my tsconfig.json, it gets passed in by $.typescript.createProject()
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"target": "ES6",
"sourceMap": true,
"outDir": "build/server"
}
}
.babelrc
{
"presets": ["es2015"]
}
Here is the relevant npm packages
"devDependencies": {
"babel-polyfill": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"gulp-babel": "^6.1.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-typescript": "^2.9.2"
}
Edit: I have done some investigating into the gulp-sourcemaps, and when not using babel the sourcemaps work properly. (Removed all irrelevant info)
src/server/up/up2/four.ts - No Babel
{
"history": [ "/home/user/code/test/src/server/up/up2/four.js" ],
"base": "/home/user/code/test/src/server/",
"sourceMap": {
"sources": ["up/up2/four.ts"],
"file": "up/up2/four.js"
}
}
Notice how in sourceMap.sources
it lists the proper source file up/up2/four.ts
Now here is an example when I add gulp-babel into the task.
src/server/up/up2/four.ts - With Babel
{
"history": [ "/home/user/code/test/src/server/up/up2/four.js" ],
"base": "/home/user/code/test/src/server/",
"sourceMap": {
"sources": ["four.js"],
"file": "up/up2/four.js"
},
"babel": {
"...": "..."
}
}
Notice how the sourceMap.sources
now incorrectly shows the four.js
instead of the typescript file.
Curiously enough, as long as the typescript files are in the root directory src/server
they build the source maps just fine.
src/server/two.ts - With Babel
{
"history": [ "/home/user/code/test/src/server/two.js" ],
"base": "/home/user/code/test/src/server/",
"sourceMap": {
"sources": ["two.ts"],
"file": "two.js"
},
"babel": {
"...": "..."
}
}