Skip to content

Commit 8e55e4d

Browse files
authored
build: correct the js rollup watch path (#2074)
1. Correct the rollup watch path 2. Avoid registering watch listeners redundantly across multiple tasks
1 parent b4019f3 commit 8e55e4d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

rollup.config.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const DIST = 'assets/js/dist';
1111
const banner = `/*!
1212
* ${pkg.name} v${pkg.version} | © ${pkg.since} ${pkg.author} | ${pkg.license} Licensed | ${pkg.homepage}
1313
*/`;
14-
1514
const frontmatter = `---\npermalink: /:basename\n---\n`;
16-
1715
const isProd = process.env.BUILD === 'production';
1816

17+
let hasWatched = false;
18+
1919
function cleanup() {
2020
fs.rmSync(DIST, { recursive: true, force: true });
2121
console.log(`> Directory "${DIST}" has been cleaned.`);
@@ -39,6 +39,11 @@ function build(
3939
{ src = SRC_DEFAULT, jekyll = false, outputName = null } = {}
4040
) {
4141
const input = `${src}/${filename}.js`;
42+
const shouldWatch = hasWatched ? false : true;
43+
44+
if (!hasWatched) {
45+
hasWatched = true;
46+
}
4247

4348
return {
4449
input,
@@ -49,9 +54,7 @@ function build(
4954
banner,
5055
sourcemap: !isProd && !jekyll
5156
},
52-
watch: {
53-
include: input
54-
},
57+
...(shouldWatch && { watch: { include: `${SRC_DEFAULT}/**/*.js` } }),
5558
plugins: [
5659
babel({
5760
babelHelpers: 'bundled',

0 commit comments

Comments
 (0)