build: 👷 Build service worker with swc
This commit is contained in:
parent
7df330ec29
commit
1540db7af9
24
packages/sw/.swcrc
Normal file
24
packages/sw/.swcrc
Normal 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
|
||||||
|
}
|
@ -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));
|
|
||||||
});
|
|
@ -2,9 +2,9 @@
|
|||||||
"name": "sw",
|
"name": "sw",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch": "node build.js watch",
|
"build": "pnpm swc src -d built -D",
|
||||||
"build": "node build.js",
|
"watch": "pnpm swc src -d built -D -w",
|
||||||
"lint": "pnpm rome check src/**/*.{ts}"
|
"lint": "pnpm rome check \"src/**/*.ts\""
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"calckey-js": "^0.0.20",
|
"calckey-js": "^0.0.20",
|
||||||
|
Loading…
Reference in New Issue
Block a user