mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 03:17:38 -07:00
build: 👷 Build service worker with swc
This commit is contained in:
parent
42902cc8a6
commit
4928df1be8
3 changed files with 27 additions and 40 deletions
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 a new issue