darionco / rollup-plugin-web-worker-loader

Rollup plugin to load Workers. Supports inlining, dependencies, source maps, NodeJS and browsers.
MIT License
112 stars 31 forks source link

rollup watch broken #38

Closed Waxolunist closed 3 years ago

Waxolunist commented 3 years ago

When using the plugin the watch mode is broken. My webworker is written with ts.

My config looks like this:

resolve(),
  workerLoader({inline: false, sourcemap: false}),
  typescript({
    sourceMap: true,
    exclude: ['node_modules', '**/*.test.ts'],
  }),

The watch mode executes the build, but the files generated are the same as before. The workaround currently used is this:

npm run clean && rollup -c && chokidar 'src/**/*.*' -c 'rollup -c'

But the builds are only half as fast as with rollup watchmode enabled.

My repository is this: https://github.com/Waxolunist/paint2

To reproduce start the watchmode and the devserver:

`npm bin`/rollup -cw
npm run serve

When changing a file (e.g. changing the html in paint-app.ts) the changes are not written to the bundle directory. Commenting out the workerLoader plugin in rollup.config.js changes are picked up immediately, so I assume the workerLoader plugin is something doing to the cache.

darionco commented 3 years ago

This one had me scratching my head for a while, I found that there's an incompatibility between the way this plugin works and @rollup/plugin-typescript I think they are doing something that caches files outside of rollup's cache, so when this plugin runs a second instance of rollup to bundle the worker files something breaks internally.

The immediate solution is to replace @rollup/plugin-typescript for rollup-plugin-typescript2 (should be a drop-in replacement).

In the long term I'll try to get in contact with the @rollup/plugin-typescript authors to try to figure out a long term solution.

Thanks for the report! also, kudos on the painter app!

closing for now, feel free to re-open if the issues persist.

EDIT: Also I would recommend adding chunkFileNames: '[name].js' to config.output to avoid generating a bunch of new files when the watch build is triggered again.

Waxolunist commented 3 years ago

Thanks for the heads up and the tip with the chunkfilenames.