build: correct the js rollup watch path (#2074)

1. Correct the rollup watch path
2. Avoid registering watch listeners redundantly across multiple tasks
This commit is contained in:
Cotes Chung 2024-12-01 04:20:47 +08:00 committed by GitHub
parent b4019f3517
commit 8e55e4dcb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,11 +11,11 @@ const DIST = 'assets/js/dist';
const banner = `/*!
* ${pkg.name} v${pkg.version} | © ${pkg.since} ${pkg.author} | ${pkg.license} Licensed | ${pkg.homepage}
*/`;
const frontmatter = `---\npermalink: /:basename\n---\n`;
const isProd = process.env.BUILD === 'production';
let hasWatched = false;
function cleanup() {
fs.rmSync(DIST, { recursive: true, force: true });
console.log(`> Directory "${DIST}" has been cleaned.`);
@ -39,6 +39,11 @@ function build(
{ src = SRC_DEFAULT, jekyll = false, outputName = null } = {}
) {
const input = `${src}/${filename}.js`;
const shouldWatch = hasWatched ? false : true;
if (!hasWatched) {
hasWatched = true;
}
return {
input,
@ -49,9 +54,7 @@ function build(
banner,
sourcemap: !isProd && !jekyll
},
watch: {
include: input
},
...(shouldWatch && { watch: { include: `${SRC_DEFAULT}/**/*.js` } }),
plugins: [
babel({
babelHelpers: 'bundled',