2023-04-10 19:43:15 +09:00
|
|
|
// @ts-check
|
|
|
|
|
2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-14 00:59:27 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-07-09 17:19:07 +09:00
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import * as esbuild from 'esbuild';
|
|
|
|
import locales from '../../locales/index.js';
|
2024-06-13 10:18:01 +09:00
|
|
|
import meta from '../../package.json' with { type: "json" };
|
2022-04-30 21:52:07 +09:00
|
|
|
const watch = process.argv[2]?.includes('watch');
|
|
|
|
|
2023-07-09 17:19:07 +09:00
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
|
|
|
|
2022-04-30 21:52:07 +09:00
|
|
|
console.log('Starting SW building...');
|
|
|
|
|
2023-04-10 19:43:15 +09:00
|
|
|
/** @type {esbuild.BuildOptions} */
|
|
|
|
const buildOptions = {
|
|
|
|
absWorkingDir: __dirname,
|
2022-04-30 21:52:07 +09:00
|
|
|
bundle: true,
|
2023-04-10 19:43:15 +09: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 21:52:07 +09:00
|
|
|
format: 'esm',
|
2023-04-10 19:43:15 +09:00
|
|
|
loader: {
|
|
|
|
'.ts': 'ts',
|
|
|
|
},
|
2022-04-30 21:52:07 +09:00
|
|
|
minify: process.env.NODE_ENV === 'production',
|
|
|
|
outbase: `${__dirname}/src`,
|
|
|
|
outdir: `${__dirname}/../../built/_sw_dist_`,
|
2023-04-10 19:43:15 +09:00
|
|
|
treeShaking: true,
|
2022-04-30 21:52:07 +09:00
|
|
|
tsconfig: `${__dirname}/tsconfig.json`,
|
2023-04-10 19:43:15 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
if (!watch) {
|
|
|
|
await esbuild.build(buildOptions);
|
|
|
|
console.log('done');
|
|
|
|
} else {
|
|
|
|
const context = await esbuild.context(buildOptions);
|
|
|
|
await context.watch();
|
|
|
|
console.log('watching...');
|
|
|
|
}
|
|
|
|
})();
|