2023-04-10 12:43:15 +02:00
|
|
|
// @ts-check
|
|
|
|
|
2023-07-09 10:19:07 +02:00
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import * as esbuild from 'esbuild';
|
|
|
|
import locales from '../../locales/index.js';
|
|
|
|
import meta from '../../package.json' assert { type: "json" };
|
2022-04-30 14:52:07 +02:00
|
|
|
const watch = process.argv[2]?.includes('watch');
|
|
|
|
|
2023-07-09 10:19:07 +02:00
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
|
|
|
|
2022-04-30 14:52:07 +02:00
|
|
|
console.log('Starting SW building...');
|
|
|
|
|
2023-04-10 12:43:15 +02:00
|
|
|
/** @type {esbuild.BuildOptions} */
|
|
|
|
const buildOptions = {
|
|
|
|
absWorkingDir: __dirname,
|
2022-04-30 14:52:07 +02:00
|
|
|
bundle: true,
|
2023-04-10 12:43:15 +02:00
|
|
|
define: {
|
|
|
|
_DEV_: JSON.stringify(process.env.NODE_ENV !== 'production'),
|
|
|
|
_ENV_: JSON.stringify(process.env.NODE_ENV ?? ''), // `NODE_ENV`が`undefined`なとき`JSON.stringify`が`undefined`を返してエラーになってしまうので`??`を使っている
|
|
|
|
_LANGS_: JSON.stringify(Object.entries(locales).map(([k, v]) => [k, v._lang_])),
|
|
|
|
_PERF_PREFIX_: JSON.stringify('Misskey:'),
|
|
|
|
_VERSION_: JSON.stringify(meta.version),
|
|
|
|
},
|
|
|
|
entryPoints: [`${__dirname}/src/sw.ts`],
|
2022-04-30 14:52:07 +02:00
|
|
|
format: 'esm',
|
2023-04-10 12:43:15 +02:00
|
|
|
loader: {
|
|
|
|
'.ts': 'ts',
|
|
|
|
},
|
2022-04-30 14:52:07 +02:00
|
|
|
minify: process.env.NODE_ENV === 'production',
|
|
|
|
outbase: `${__dirname}/src`,
|
|
|
|
outdir: `${__dirname}/../../built/_sw_dist_`,
|
2023-04-10 12:43:15 +02:00
|
|
|
treeShaking: true,
|
2022-04-30 14:52:07 +02:00
|
|
|
tsconfig: `${__dirname}/tsconfig.json`,
|
2023-04-10 12:43:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
if (!watch) {
|
|
|
|
await esbuild.build(buildOptions);
|
|
|
|
console.log('done');
|
|
|
|
} else {
|
|
|
|
const context = await esbuild.context(buildOptions);
|
|
|
|
await context.watch();
|
|
|
|
console.log('watching...');
|
|
|
|
}
|
|
|
|
})();
|