1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-11 21:29:13 +09:00
misskey/packages/sw/build.js
Kagami Sascha Rosylight 59046d583d
refactor(locales, sw): use es module (#11204)
* refactor(locales): use es module

* fix sw build

* fix gulp

* try fixing storybook

* Revert "try fixing storybook"

This reverts commit 5f2a4eee01.

* try fixing storybook 2

* Update main.ts

* Update build.js

* Update main.ts

* Update changes.ts

* fix sw lint

* Update build.js
2023-07-09 17:19:07 +09:00

46 lines
1.4 KiB
JavaScript

// @ts-check
import { fileURLToPath } from 'node:url';
import * as esbuild from 'esbuild';
import locales from '../../locales/index.js';
import meta from '../../package.json' assert { type: "json" };
const watch = process.argv[2]?.includes('watch');
const __dirname = fileURLToPath(new URL('.', import.meta.url))
console.log('Starting SW building...');
/** @type {esbuild.BuildOptions} */
const buildOptions = {
absWorkingDir: __dirname,
bundle: true,
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`],
format: 'esm',
loader: {
'.ts': 'ts',
},
minify: process.env.NODE_ENV === 'production',
outbase: `${__dirname}/src`,
outdir: `${__dirname}/../../built/_sw_dist_`,
treeShaking: true,
tsconfig: `${__dirname}/tsconfig.json`,
};
(async () => {
if (!watch) {
await esbuild.build(buildOptions);
console.log('done');
} else {
const context = await esbuild.context(buildOptions);
await context.watch();
console.log('watching...');
}
})();