Skip to content

Commit

Permalink
swのesbuildの更新とビルドスクリプトの更新 (#10549)
Browse files Browse the repository at this point in the history
* 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`になる場合がある問題を修正

コメントの文言を調整
  • Loading branch information
okayurisotto authored Apr 10, 2023
1 parent 511dab0 commit 6a23ffc
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 242 deletions.
53 changes: 29 additions & 24 deletions packages/sw/build.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
// @ts-check

const esbuild = require('esbuild');
const locales = require('../../locales');
const meta = require('../../package.json');
const watch = process.argv[2]?.includes('watch');

console.log('Starting SW building...');

esbuild.build({
entryPoints: [ `${__dirname}/src/sw.ts` ],
/** @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',
treeShaking: true,
loader: {
'.ts': 'ts',
},
minify: process.env.NODE_ENV === 'production',
absWorkingDir: __dirname,
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...');
}
})();
2 changes: 1 addition & 1 deletion packages/sw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "pnpm typecheck && pnpm eslint"
},
"dependencies": {
"esbuild": "0.14.42",
"esbuild": "0.17.15",
"idb-keyval": "6.2.0",
"misskey-js": "workspace:*"
},
Expand Down
Loading

0 comments on commit 6a23ffc

Please sign in to comment.