jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.2k stars 505 forks source link

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

Open Kinco4TC opened 2 years ago

Kinco4TC commented 2 years ago

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!

agilgur5 commented 2 years ago

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.