From be07b20da9c575088300ec36898d87a32f1fddd2 Mon Sep 17 00:00:00 2001 From: Scott Gould Date: Thu, 19 Sep 2024 23:55:27 -0400 Subject: [PATCH] Use SWC by default --- gulpfile.cjs | 43 +++++++++++++++++++++++++++++++++++++++++-- package.json | 2 ++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gulpfile.cjs b/gulpfile.cjs index 2e9f80f..89d11f6 100644 --- a/gulpfile.cjs +++ b/gulpfile.cjs @@ -1,10 +1,49 @@ const gulp = require("gulp"); const ts = require("gulp-typescript"); +const swc = require("gulp-swc"); const tsProject = ts.createProject("tsconfig.json"); +const argv = require("yargs").argv; -// Task to compile TypeScript files +const swcOptions = { + 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: "inline", + minify: false, +}; + +// Task to compile TypeScript files using SWC gulp.task("scripts", () => { - return tsProject.src().pipe(tsProject()).js.pipe(gulp.dest("dist")); + if (argv.ts) { + console.warn("[WARN] Using TSC compiler, will be slower than SWC"); + return gulp.src("src/**/*.ts").pipe(tsProject()).pipe(gulp.dest("dist")); + } else { + return gulp + .src("src/**/*.ts") + .pipe(swc(swcOptions)) + .pipe(gulp.dest("dist")); + } }); // Task to copy HTML files diff --git a/package.json b/package.json index f183dfa..0c96608 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,13 @@ "dependencies": { "@html-eslint/parser": "^0.27.0", "@stylistic/eslint-plugin-js": "^2.8.0", + "@swc/core": "^1.7.26", "@typescript-eslint/eslint-plugin": "^8.6.0", "@typescript-eslint/parser": "^8.6.0", "compression": "^1.7.4", "eslint-plugin-html": "^8.1.1", "express": "^4.19.2", + "gulp-swc": "^2.2.0", "node-fetch": "^3.3.2", "ts-to-jsdoc": "^2.2.0" },