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