build: 👷 Build service worker with swc

This commit is contained in:
ThatOneCalculator 2023-01-24 15:09:09 -08:00
parent 7df330ec29
commit 1540db7af9
No known key found for this signature in database
GPG key ID: 8703CACD01000000
3 changed files with 27 additions and 40 deletions

24
packages/sw/.swcrc Normal file
View file

@ -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
}

View file

@ -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));
});

View file

@ -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",