-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
511dab0
commit 6a23ffc
Showing
3 changed files
with
245 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...'); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.