type: module support for older browsers with worker-plugin
Closed this issue · 2 comments
Hey,
First of all, thanks for worker-plugin
- I'm really enjoying using it. I found myself pondering a question and the docs don't seem to answer it. So I thought I'd raise it as a question (and a great outcome of this issue could be me raising a docs PR so others get the benefit too)
Consider:
const worker = new Worker('./foo.js', { type: 'module' });
I love { type: 'module' }
because it provides the ability for standard import
module syntax that I'm entirely used to. Honestly, I've never sufficiently understood importScripts
, and given that I'm used to ES modules I'd rather stick with one way to do modules rather than two.
As I understand it, { type: 'module' }
has only recently started being supported in Chrome and is only supported there so far. Most of my users aren't on the latest greatest Chrome.
Does worker-plugin
require that { type: 'module' }
is in the browser to work, or does it do some clever transpilation / shimming so that's not a problem?
Hi @johnnyreilly! Sorry for the slow reply.
Worker Plugin actually compiles { type:'module' }
away and outputs standard non-module Workers, so the output is fully supported in IE10+.
Effectively, Worker Plugin just uses { type:'module' }
as a way for you to indicate that the URL/filename of the worker is a module Webpack can then start bundling from.
Great news! Thanks!