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 next workflow.
Typescript (ES6) -> Babel (ES6) -> ES5
Now I'm using Gulp to automate all of this, and it's hard for me to get the source maps to generate properly. I should mention that this style was suggested to me by the user in / r / typescript, so I'm not even sure if this is possible.
Anyway, 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 tried many different approaches, but no one works. When debugging in VSCode, the entry point of my application: build/server/index.js loads and correctly finds the source file src/server/index.ts .
However, when VSCode tries to move to another file, say build/server/utils/logger/index.js , it looks for src/server/utils/logger/index.js , which it does not find, because it should look for * .ts file.
So what am I doing wrong? Or is it even possible? I watched it for about 5 hours. Therefore, any understanding would be wonderful.
Also VSCode 0.9.x displays '.../.js' file not found , and VSCode 1.0 just fails.
my tsconfig.json, it goes through $.typescript.createProject()
{ "compilerOptions": { "module": "commonjs", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, "target": "ES6", "sourceMap": true, "outDir": "build/server" } }
.babelrc
{ "presets": ["es2015"] }
Here are 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 did some research on gulp -sourcemaps, and when you are not using babel, sourcemaps files work correctly. (Removed all irrelevant information)
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" } }
Note that in sourceMap.sources it lists the correct source file up/up2/four.ts
Now here is an example when I add gulp-babel to a 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": { "...": "..." } }
Note that sourceMap.sources now incorrectly displays four.js instead of the TypeScript file.
Curiously, as long as the TypeScript files are in the root directory of src/server , they correctly build the source maps.
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": { "...": "..." } }