Skip to content

How does watch mode work? #295

Description

@NullVoxPopuli

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions