Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does watch mode work? #295

Open
NullVoxPopuli opened this issue Mar 21, 2023 · 0 comments
Open

How does watch mode work? #295

NullVoxPopuli opened this issue Mar 21, 2023 · 0 comments

Comments

@NullVoxPopuli
Copy link
Contributor

NullVoxPopuli commented Mar 21, 2023

Environment

node 18, webpack 5

Reproduction

I have this plugin that I'm using in webpack:

const { createUnplugin } = require('unplugin');

const copyToPublic = createUnplugin((options) => {
  let { src, include, dest } = options ?? {};

  dest ??= src;
  include ??= '**/*';

  return {
    name: 'copy-files-to-public',
    async buildStart() {
      const files = globby.sync(include, { cwd: src });

      await Promise.all(
        files.map(async (file) => {
          let source = path.join(src, file);

          this.addWatchFile(source);

          await this.emitFile({
            type: 'asset',
            fileName: path.join(dest, file),
            source: fs.readFileSync(source).toString(),
          });
        })
      );
    },
  };
});

Like this:

        plugins: [
          copyToPublic.webpack({ src: 'docs' }),

        ],
      },

Describe the bug

when I tried to use the watchChange hook, it was never called (no console.log's were logged)
(I made sure to change a few of the files found by globby)

Additional context

No response

Logs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant