updates to gulp file
This commit is contained in:
parent
5e5da7d10a
commit
731e5d5ee7
2 changed files with 77 additions and 97 deletions
67
gulpfile.cjs
67
gulpfile.cjs
|
@ -1,40 +1,12 @@
|
||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
const ts = require("gulp-typescript");
|
const ts = require("gulp-typescript");
|
||||||
const swc = require("gulp-swc");
|
|
||||||
const tsProject = ts.createProject("tsconfig.json");
|
const tsProject = ts.createProject("tsconfig.json");
|
||||||
const argv = require("yargs").argv;
|
const argv = require("yargs").argv;
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
const plumber = require("gulp-plumber");
|
const plumber = require("gulp-plumber");
|
||||||
const sourcemaps = require("gulp-sourcemaps");
|
const sourcemaps = require("gulp-sourcemaps");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const swcOptions = {
|
const {swcDir} = require("@swc/cli");
|
||||||
jsc: {
|
|
||||||
parser: {
|
|
||||||
syntax: "typescript",
|
|
||||||
tsx: false,
|
|
||||||
decorators: true,
|
|
||||||
dynamicImport: true,
|
|
||||||
},
|
|
||||||
transform: {
|
|
||||||
react: {
|
|
||||||
runtime: "automatic",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
target: "es2022",
|
|
||||||
loose: false,
|
|
||||||
externalHelpers: false,
|
|
||||||
keepClassNames: true,
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
type: "es6",
|
|
||||||
strict: true,
|
|
||||||
strictMode: true,
|
|
||||||
lazy: false,
|
|
||||||
noInterop: false,
|
|
||||||
},
|
|
||||||
sourceMaps: true,
|
|
||||||
minify: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
gulp.task(
|
gulp.task(
|
||||||
"watch",
|
"watch",
|
||||||
|
@ -49,25 +21,34 @@ gulp.task(
|
||||||
gulp.task("clean", (cb) => {
|
gulp.task("clean", (cb) => {
|
||||||
return rimraf.rimraf("dist").then(cb());
|
return rimraf.rimraf("dist").then(cb());
|
||||||
});
|
});
|
||||||
const exec = require("child_process").exec;
|
|
||||||
// Task to compile TypeScript files using SWC
|
// Task to compile TypeScript files using SWC
|
||||||
gulp.task("scripts", async () => {
|
gulp.task("scripts", async () => {
|
||||||
if (argv.swc) {
|
if (argv.swc || argv.bunswc) {
|
||||||
return gulp
|
|
||||||
.src("src/**/*.ts")
|
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(plumber()) // Prevent pipe breaking caused by errors
|
|
||||||
.pipe(swc(swcOptions))
|
|
||||||
.pipe(sourcemaps.write("."))
|
|
||||||
.pipe(gulp.dest("dist"));
|
|
||||||
} else if (argv.bunswc) {
|
|
||||||
return await new Promise((ret) => {
|
return await new Promise((ret) => {
|
||||||
exec("bun swc --strip-leading-paths ./src -s -d ./dist/ -C jsc.target=es2022").on(
|
swcDir({
|
||||||
"exit",
|
cliOptions: {
|
||||||
function (code) {
|
outDir: "./dist",
|
||||||
|
watch: true,
|
||||||
|
filenames: ["./src"],
|
||||||
|
extensions: [".ts"],
|
||||||
|
stripLeadingPaths: true,
|
||||||
|
"no-swcrc": true,
|
||||||
|
},
|
||||||
|
callbacks: {
|
||||||
|
onSuccess: (e) => {
|
||||||
|
ret();
|
||||||
|
console.log(e);
|
||||||
|
},
|
||||||
|
onFail: (e) => {
|
||||||
|
for ([, reason] of e.reasons) {
|
||||||
|
console.log(reason);
|
||||||
|
}
|
||||||
ret();
|
ret();
|
||||||
},
|
},
|
||||||
);
|
onWatchReady: () => {},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.warn("[WARN] Using TSC compiler, will be slower than SWC");
|
console.warn("[WARN] Using TSC compiler, will be slower than SWC");
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"gulp-sourcemaps": "^2.6.5",
|
"gulp-sourcemaps": "^2.6.5",
|
||||||
"gulp-swc": "^2.2.0",
|
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
"rimraf": "^6.0.1"
|
"rimraf": "^6.0.1"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue