swのesbuildの更新とビルドスクリプトの更新 (#10549)
* cleanup(sw/build.js) * fix(sw/build.js): `define`に真偽値を渡していた問題を修正 `define`では文字列を渡さなければならないので、`JSON.stringify`をするようにした。 * fix(sw/build.js): `string`が期待される`define`において`undefined`になる場合がある問題を修正 * update(sw): esbuild 0.17.15 * fixup! update(sw): esbuild 0.17.15 * fixup! fix(sw/build.js): `string`が期待される`define`において`undefined`になる場合がある問題を修正 コメントの文言を調整
This commit is contained in:
parent
511dab0618
commit
6a23ffcce5
3 changed files with 247 additions and 244 deletions
|
@ -1,3 +1,5 @@
|
|||
// @ts-check
|
||||
|
||||
const esbuild = require('esbuild');
|
||||
const locales = require('../../locales');
|
||||
const meta = require('../../package.json');
|
||||
|
@ -5,33 +7,36 @@ const watch = process.argv[2]?.includes('watch');
|
|||
|
||||
console.log('Starting SW building...');
|
||||
|
||||
esbuild.build({
|
||||
entryPoints: [ `${__dirname}/src/sw.ts` ],
|
||||
bundle: true,
|
||||
format: 'esm',
|
||||
treeShaking: true,
|
||||
minify: process.env.NODE_ENV === 'production',
|
||||
/** @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_`,
|
||||
loader: {
|
||||
'.ts': 'ts'
|
||||
},
|
||||
treeShaking: true,
|
||||
tsconfig: `${__dirname}/tsconfig.json`,
|
||||
define: {
|
||||
_VERSION_: JSON.stringify(meta.version),
|
||||
_LANGS_: JSON.stringify(Object.entries(locales).map(([k, v]) => [k, v._lang_])),
|
||||
_ENV_: JSON.stringify(process.env.NODE_ENV),
|
||||
_DEV_: process.env.NODE_ENV !== 'production',
|
||||
_PERF_PREFIX_: JSON.stringify('Misskey:'),
|
||||
},
|
||||
watch: watch ? {
|
||||
onRebuild(error, result) {
|
||||
if (error) console.error('SW: watch build failed:', error);
|
||||
else console.log('SW: watch build succeeded:', result);
|
||||
},
|
||||
} : false,
|
||||
}).then(result => {
|
||||
if (watch) console.log('watching...');
|
||||
else console.log('done,', JSON.stringify(result));
|
||||
});
|
||||
};
|
||||
|
||||
(async () => {
|
||||
if (!watch) {
|
||||
await esbuild.build(buildOptions);
|
||||
console.log('done');
|
||||
} else {
|
||||
const context = await esbuild.context(buildOptions);
|
||||
await context.watch();
|
||||
console.log('watching...');
|
||||
}
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue