GoogleChromeLabs / worker-plugin

👩‍🏭 Adds native Web Worker bundling support to Webpack.
https://npm.im/worker-plugin
Apache License 2.0
1.91k stars 79 forks source link

how to change directory of worker? #71

Closed stephenjason89 closed 4 years ago

stephenjason89 commented 4 years ago

im using laravel mix and by default it places the file at public directory

here's my webpack Config

.webpackConfig({ plugins: [ new WorkerPlugin({ filename: '[name].worker.js' }) ], });

if i use the output

output: { path: path.join(__dirname, 'public/js/workers'), },

It places all my files there including my app.js which i don't want

Thank you for the help

developit commented 4 years ago

I believe this should work without any configuration:

new Worker("./calculate-primes.js", {
  type: "module",
  name: "workers/calculate-primes",
});

FWIW this plugin will use output.chunkFilename if you define it:

output: {
  path: path.join(__dirname, 'public/js'),
  filename: '[name].js',
  chunkFilename: 'chunks/[name].js',  // <-- public/js/chunks/calculate-primes.worker.js
},
stephenjason89 commented 4 years ago

Thank you sir.