From 4928df1be8c1f21342c2f389c17658815e8de800 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Tue, 24 Jan 2023 15:09:09 -0800 Subject: [PATCH] build: :construction_worker: Build service worker with swc --- packages/sw/.swcrc | 24 ++++++++++++++++++++++++ packages/sw/build.js | 37 ------------------------------------- packages/sw/package.json | 6 +++--- 3 files changed, 27 insertions(+), 40 deletions(-) create mode 100644 packages/sw/.swcrc delete mode 100644 packages/sw/build.js diff --git a/packages/sw/.swcrc b/packages/sw/.swcrc new file mode 100644 index 000000000..1d6d3b496 --- /dev/null +++ b/packages/sw/.swcrc @@ -0,0 +1,24 @@ +{ + "$schema": "https://json.schemastore.org/swcrc", + "jsc": { + "parser": { + "syntax": "typescript", + "dynamicImport": true, + "decorators": true + }, + "transform": { + "decoratorMetadata": true + }, + "experimental": { + "keepImportAssertions": true + }, + "baseUrl": ".", + "paths": { + "@/*": [ + "./src/*" + ] + }, + "target": "es2022" + }, + "minify": false +} diff --git a/packages/sw/build.js b/packages/sw/build.js deleted file mode 100644 index c2a72fa4e..000000000 --- a/packages/sw/build.js +++ /dev/null @@ -1,37 +0,0 @@ -const esbuild = require('esbuild'); -const locales = require('../../locales'); -const meta = require('../../package.json'); -const watch = process.argv[2]?.includes('watch'); - -console.log('Starting SW building...'); - -esbuild.build({ - entryPoints: [ `${__dirname}/src/sw.ts` ], - bundle: true, - format: 'esm', - treeShaking: true, - minify: process.env.NODE_ENV === 'production', - absWorkingDir: __dirname, - outbase: `${__dirname}/src`, - outdir: `${__dirname}/../../built/_sw_dist_`, - loader: { - '.ts': 'ts' - }, - tsconfig: `${__dirname}/tsconfig.json`, - define: { - _VERSION_: JSON.stringify(meta.version), - _LANGS_: JSON.stringify(Object.entries(locales).map(([k, v]) => [k, v._lang_])), - _ENV_: JSON.stringify(process.env.NODE_ENV), - _DEV_: process.env.NODE_ENV !== 'production', - _PERF_PREFIX_: JSON.stringify('Calckey:'), - }, - watch: watch ? { - onRebuild(error, result) { - if (error) console.error('SW: watch build failed:', error); - else console.log('SW: watch build succeeded:', result); - }, - } : false, -}).then(result => { - if (watch) console.log('watching...'); - else console.log('done,', JSON.stringify(result)); -}); diff --git a/packages/sw/package.json b/packages/sw/package.json index 41bdb0da8..ab22ca73f 100644 --- a/packages/sw/package.json +++ b/packages/sw/package.json @@ -2,9 +2,9 @@ "name": "sw", "private": true, "scripts": { - "watch": "node build.js watch", - "build": "node build.js", - "lint": "pnpm rome check src/**/*.{ts}" + "build": "pnpm swc src -d built -D", + "watch": "pnpm swc src -d built -D -w", + "lint": "pnpm rome check \"src/**/*.ts\"" }, "dependencies": { "calckey-js": "^0.0.20",