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:
parent
b4019f3517
commit
8e55e4dcb2
1 changed files with 8 additions and 5 deletions
|
@ -11,11 +11,11 @@ const DIST = 'assets/js/dist';
|
||||||
const banner = `/*!
|
const banner = `/*!
|
||||||
* ${pkg.name} v${pkg.version} | © ${pkg.since} ${pkg.author} | ${pkg.license} Licensed | ${pkg.homepage}
|
* ${pkg.name} v${pkg.version} | © ${pkg.since} ${pkg.author} | ${pkg.license} Licensed | ${pkg.homepage}
|
||||||
*/`;
|
*/`;
|
||||||
|
|
||||||
const frontmatter = `---\npermalink: /:basename\n---\n`;
|
const frontmatter = `---\npermalink: /:basename\n---\n`;
|
||||||
|
|
||||||
const isProd = process.env.BUILD === 'production';
|
const isProd = process.env.BUILD === 'production';
|
||||||
|
|
||||||
|
let hasWatched = false;
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
fs.rmSync(DIST, { recursive: true, force: true });
|
fs.rmSync(DIST, { recursive: true, force: true });
|
||||||
console.log(`> Directory "${DIST}" has been cleaned.`);
|
console.log(`> Directory "${DIST}" has been cleaned.`);
|
||||||
|
@ -39,6 +39,11 @@ function build(
|
||||||
{ src = SRC_DEFAULT, jekyll = false, outputName = null } = {}
|
{ src = SRC_DEFAULT, jekyll = false, outputName = null } = {}
|
||||||
) {
|
) {
|
||||||
const input = `${src}/${filename}.js`;
|
const input = `${src}/${filename}.js`;
|
||||||
|
const shouldWatch = hasWatched ? false : true;
|
||||||
|
|
||||||
|
if (!hasWatched) {
|
||||||
|
hasWatched = true;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
input,
|
input,
|
||||||
|
@ -49,9 +54,7 @@ function build(
|
||||||
banner,
|
banner,
|
||||||
sourcemap: !isProd && !jekyll
|
sourcemap: !isProd && !jekyll
|
||||||
},
|
},
|
||||||
watch: {
|
...(shouldWatch && { watch: { include: `${SRC_DEFAULT}/**/*.js` } }),
|
||||||
include: input
|
|
||||||
},
|
|
||||||
plugins: [
|
plugins: [
|
||||||
babel({
|
babel({
|
||||||
babelHelpers: 'bundled',
|
babelHelpers: 'bundled',
|
||||||
|
|
Loading…
Reference in a new issue