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

Is it possible not to include the .worker. in the filename? #76

Closed wood1986 closed 4 years ago

wood1986 commented 4 years ago

https://github.com/GoogleChromeLabs/worker-plugin/blob/7dc17f0fc971bd27b3bfe99060554abd9e61276f/src/loader.js#L41

I have a naming pattern for all the chunks which is <name>.<hash>.<ext>. Because of worker.js I have to do some work to handle this special and only case.

I am using inline loader "worker-plugin/loader!./worker";

developit commented 4 years ago

This is a bit tricky, because removing the suffix can lead to name collisions. When you're injecting a hash it's extremely unlikely that collisions would occur, but the plugin can't really determine that a hash is going to be used when it generates the filename template.

That being said, I think we can definitely add support for custom name templates. I've just opened a PR that adds this:

new WorkerPlugin({
    filename: '[name].[hash:5].js',
    chunkFilename: '[name].[hash:5].js',
})

... as well as a version for loaders:

import Worker from "worker-plugin/loader?filename=foo.[hash:5].js!./worker";