Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying URL in web worker chunk #16

Closed
sushain97 opened this issue Apr 2, 2019 · 8 comments
Closed

Modifying URL in web worker chunk #16

sushain97 opened this issue Apr 2, 2019 · 8 comments
Assignees

Comments

@sushain97
Copy link

I'm running to issues with an inline web worker with a dynamic import not being intercepted by this library. Since inline web workers are blobs and therefore need an absolute URL to successfully import scripts, I'm attempting to use this library to fix-up the URL.

e.g.

const md = await import(/* webpackChunkName: "markdown-it" */ 'markdown-it');

inside a web worker becomes something like

const md = await __webpack_require__.e(/* import() | markdown-it */ 2).then(__webpack_require__.t.bind(null, 264, 7));

which calls into

r.e = function(e) {
        var n = [];
        return n.push(Promise.resolve().then(function() {
            t[e] || importScripts(e + ".ee0bc93119ec2d63cc28.worker.js")
        })),
        Promise.all(n)
    }

Unfortunately, this isn't prepending the path it should be per the config below since it never actually results in the code below being called.

Object.defineProperty(r, "p", {
        get: function() {
            return "http://localhost:8080/"
        }
    }),
new WebpackRequireFrom({
      path: 'http://localhost:8080/',
      suppressErrors: true,
    }),

(For now, I've used a hardcoded path to see if I could get it minimally working. In practice, it would be a variable that is set similar to the advice in https://stackoverflow.com/a/22582695/1266600.)

Am I misunderstanding how something works or perhaps the intent of this library?

@agoldis
Copy link
Owner

agoldis commented Apr 2, 2019

Hi @sushain97! Thanks for discovering and reporting that issue!
Could you please share the webpack version you're using and may be a minimal reproducable example of the code.
Also, did you try to use other options, e.g. https://github.com/agoldis/webpack-require-from#replacesrcmethodname?

EDIT: Seems like the plugin doesn't support webworkers use case, I will need to implement it. I will keep you posted, prob won't take long

@agoldis agoldis self-assigned this Apr 2, 2019
@sushain97
Copy link
Author

sushain97 commented Apr 2, 2019

Awesome! Thank you for investigating (and taking up the enhancement).

FTR, my resolved Webpack version is 4.16.5.

@agoldis
Copy link
Owner

agoldis commented Apr 3, 2019

@sushain97 Can you please share your webpack config

@sushain97
Copy link
Author

@agoldis https://github.com/sushain97/web2fs-notepad/blob/issue-25/webpack.config.js

@agoldis
Copy link
Owner

agoldis commented Apr 7, 2019

@sushain97 That was an interesting problem!

Would appreciate if you try to use

yarn add https://github.com/agoldis/webpack-require-from.git#next

and follow the instructions https://github.com/agoldis/webpack-require-from/tree/next#web-worker

Although I've validated the feature and implemented a test, I'd like to make sure it is clear how to use the pluging and support your use case.

There's also a working example https://github.com/agoldis/webpack-require-from/tree/next/example

I am waiting for your feedback regarding:

  1. The documentation and instructions
  2. Whether the solution is working for you

@sushain97
Copy link
Author

The solution works for me and the documentation looks good as well! The only note I have is that since window isn't supported in a web worker, self is required instead: sushain97/web2fs-notepad@06b3ece#diff-028b78cada5fa9a59260b989f3b86ffeR52. The URL needs to be passed from the main thread to the web worker as a message (might be useful to note this as well).

Thanks for your fast (and great) work!

@agoldis
Copy link
Owner

agoldis commented Apr 9, 2019

Great, I will roll out a new npm release later this week

@agoldis
Copy link
Owner

agoldis commented Apr 15, 2019

Resolved by https://github.com/agoldis/webpack-require-from/releases/tag/v1.8.0

@agoldis agoldis closed this as completed Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants