Skip to content

Commit

Permalink
add own clean plugin
Browse files Browse the repository at this point in the history
this only cleans up deleted files.
otherwise all files are deleted everytime, which makes HMR less useful
  • Loading branch information
patricklx committed Mar 26, 2024
1 parent bac2415 commit 3883ada
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
21 changes: 21 additions & 0 deletions packages/addon-dev/src/rollup-clean-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import walkSync from 'walk-sync';
import { rmSync } from 'fs';
import { join } from 'path';
import type { Plugin } from 'rollup';

export default function clean(): Plugin {
return {
name: 'clean',
writeBundle(options, bundle) {
const files = walkSync(options.dir!, {
globs: ['*/**'],
directories: false,
});
for (const file of files) {
if (!bundle[file]) {
rmSync(join(options.dir!, file));
}
}
},
};
}
9 changes: 4 additions & 5 deletions packages/addon-dev/src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { default as hbs } from './rollup-hbs-plugin';
import { default as gjs } from './rollup-gjs-plugin';
import { default as publicEntrypoints } from './rollup-public-entrypoints';
import { default as appReexports } from './rollup-app-reexports';
import type { Options as DelOptions } from 'rollup-plugin-delete';
import { default as clean } from 'rollup-plugin-delete';
import { default as keepAssets } from './rollup-keep-assets';
import { default as dependencies } from './rollup-addon-dependencies';
import { default as publicAssets } from './rollup-public-assets';
import { default as clean } from './rollup-clean-plugin';
import type { Plugin } from 'rollup';

export class Addon {
Expand Down Expand Up @@ -62,9 +61,9 @@ export class Addon {
}

// By default rollup does not clear the output directory between builds. This
// does that.
clean(options: DelOptions) {
return clean({ targets: `${this.#destDir}/*`, ...options });
// does that. It only deletes files that are not part of the generated bundle
clean() {
return clean();
}

// V2 Addons are allowed to contain imports of .css files. This tells rollup
Expand Down

0 comments on commit 3883ada

Please sign in to comment.