gulp-typescript
gulp-typescript copied to clipboard
I can't figure out how to get source maps working.
Here's my gulpfile:
const gulp = require('gulp')
const babel = require('gulp-babel')
// const cached = require('gulp-cached')
const typescript = require('gulp-typescript')
const merge = require('merge-stream')
const babelConfig = require('./babel.config')
const tsConfig = require('./tsconfig.json')
const sourcemaps = require('gulp-sourcemaps')
function transpile() {
return merge()
}
function watch(task) {
return gulp.watch(
['src/**/*.{js,jsx,ts,tsx}', '!src/**/*test.{js,jsx,ts,tsx}'],
{ ignoreInitial: false },
gulp.parallel(task)
)
}
gulp.task('build-cjs', () => {
const jsPipe = gulp
.src(['src/**/*.{js,jsx}', '!src/**/*test.{js,jsx}'])
// .pipe(cached('js')) // in watch mode, prevents rebuilding all files
.pipe(sourcemaps.init())
.pipe(babel(babelConfig))
.pipe(
babel({
plugins: [
'@babel/plugin-transform-modules-commonjs',
'babel-plugin-add-module-exports',
],
})
)
// TODO source maps
.pipe(sourcemaps.write())
.pipe(gulp.dest('./'))
const tsPipe = gulp
.src(['src/**/*.{ts,tsx}', '!src/**/*test.{ts,tsx}'])
// .pipe(cached('ts')) // in watch mode, prevents rebuilding all files
.pipe(sourcemaps.init())
.pipe(typescript(tsConfig.compilerOptions))
.pipe(babel(babelConfig))
.pipe(
babel({
plugins: [
'@babel/plugin-transform-modules-commonjs',
'babel-plugin-add-module-exports',
],
})
)
// TODO source maps
.pipe(sourcemaps.write())
.pipe(gulp.dest('./'))
return merge(jsPipe, tsPipe)
})
gulp.task('watch-cjs', () => watch('build-cjs'))
There are no errors. An output file looks like this:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Box = exports.default = void 0;
var _Mesh = _interopRequireDefault(require("./Mesh"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Box extends _Mesh.default {}
exports.Box = exports.default = Box;
Box.defaultElementName = 'i-box';
Box.defaultBehaviors = {
'box-geometry': initialBehaviors => {
return !initialBehaviors.some(b => b.endsWith('-geometry'));
},
'phong-material': initialBehaviors => {
return !initialBehaviors.some(b => b.endsWith('-material'));
}
};
I think a sourceMapUrl should appear at the bottom, along with a sibling source map? What have I done wrong?