fix: output sourcemap correctly

This commit is contained in:
Oliver Booth 2024-03-01 17:08:23 +00:00
parent a3d941d6a2
commit 81f101e337
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5

View File

@ -40,7 +40,7 @@ function compileTS() {
return gulp.src(`${srcDir}/ts/**/*.ts`) return gulp.src(`${srcDir}/ts/**/*.ts`)
.pipe(isDevelopment ? sourcemaps.init() : noop()) .pipe(isDevelopment ? sourcemaps.init() : noop())
.pipe(ts("tsconfig.json")) .pipe(ts("tsconfig.json"))
.pipe(isDevelopment ? sourcemaps.write() : noop()) .pipe(isDevelopment ? sourcemaps.write("./", { includeContent: true }) : noop())
.pipe(gulp.dest(`tmp/js`)); .pipe(gulp.dest(`tmp/js`));
} }
@ -48,13 +48,20 @@ function bundleJS(done) {
const tasks = fs.readdirSync("tmp/js", {withFileTypes: true}) const tasks = fs.readdirSync("tmp/js", {withFileTypes: true})
.filter(dirent => dirent.isDirectory()) .filter(dirent => dirent.isDirectory())
.map(d => bundleDir(d.name)); .map(d => bundleDir(d.name));
return gulp.parallel(...tasks)(done); return gulp.parallel(...tasks, writeSourcemaps)(done);
function bundleDir(directory) { function bundleDir(directory) {
return () => gulp.src(`tmp/js/${directory}/${directory}.js`) return () => gulp.src(`tmp/js/${directory}/${directory}.js`)
.pipe(isDevelopment ? sourcemaps.init() : noop()) .pipe(isDevelopment ? sourcemaps.init() : noop())
.pipe(webpack({mode: "production", output: {filename: `${directory}.min.js`}})) .pipe(webpack({mode: "production", output: {filename: `${directory}.min.js`}, devtool: "source-map"}))
.pipe(isDevelopment ? sourcemaps.write() : noop()) .pipe(isDevelopment ? sourcemaps.write("./", { includeContent: true }) : noop())
.pipe(gulp.dest(`${destDir}/js`));
}
function writeSourcemaps() {
return gulp.src(`${destDir}/js/**/*.js`)
.pipe(isDevelopment ? sourcemaps.init({ loadMaps: true }) : noop())
.pipe(isDevelopment ? sourcemaps.write("./", { includeContent: true }) : noop())
.pipe(gulp.dest(`${destDir}/js`)); .pipe(gulp.dest(`${destDir}/js`));
} }
} }