tsdx icon indicating copy to clipboard operation
tsdx copied to clipboard

Failed to compile web worker when using `rollup-plugin-web-worker-loader`

Open Kinco4TC opened this issue 4 years ago • 1 comments

Current Behavior

Failed to compiler the web worker by using rollup-plugin-web-worker-loader. And compiler successfully by native rollup.

// Failed
const webWorkerLoader = require('rollup-plugin-web-worker-loader');
module.exports = {
  rollup(config, options) {
    config.plugins.push(webWorkerLoader());
    return config;
  },
};

// Success in native rollup
// rollup --config config.js
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
export default {
  input: 'src/index.js',
  output: {
    file: 'bundle.js',
    format: 'esm',
  },
  plugins: [webWorkerLoader(/* configuration */)],
};

Expected behavior

Success to complier the web worker

Additional context

There is a same issue in the repo of rollup-plugin-web-worker-loader : https://github.com/darionco/rollup-plugin-web-worker-loader/issues/33. But I still failed by the config offer by the author. I suppose the reason is the bug commented has been fix by tsdx team and it cause new problem in complier web worker. Plz help me!

Kinco4TC avatar Sep 10 '21 08:09 Kinco4TC

I suppose the reason is the bug commented has been fix by tsdx team and it cause new problem in complier web worker.

It has not, TSDX still "screens out" (in the author's words) any absolute paths, such as web-worker:. Kudos to him for debugging that and mostly figuring it out.

But I still failed by the config offer by the author

You didn't provide a reproduction, so it's hard to help or interpret why the author's config would fail. The author's config should work. It seems like web-worker-loader must come first, so config.plugins.unshift should be used instead of config.plugins.push in your code. And use the author's regex match on .worker with a rename of your file etc.

Then you'd remove the web-worker: prefix from your import statement. ^I suspect that last piece might be missing for some folks.

agilgur5 avatar Apr 12 '22 00:04 agilgur5