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