-
Notifications
You must be signed in to change notification settings - Fork 79
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
Allow for dynamic webpack public paths #47
Comments
@ScottPeterJohnson hmm - wouldn't this work though? The plugin generates a URL based on webpack_public_path, which you are assigning a new value to. One thing I wanted to clarify - setting webpack_public_path in your code will never change asset locations on disk. For that you need to set the |
Looking into this further it seems like the Here's what I'm looking at, though I can't find the source or documentation on how webpack does this so it's pretty much unreadable. https://gist.github.com/ScottPeterJohnson/caa0051a8bad7f287683f23b5175b61e
Admittedly I might be doing something wrong? My use case seems simple enough: I just want users of my library to be able to specify the path where my worker will be loaded from. |
@ScottPeterJohnson Sorry for the delayed reply. I think you're right that this is a timing issue, but I can't think of any way to defer WorkerPlugin's usage of I think we might be able to fix your issue though, and it doesn't require a change in webpack or Worker Plugin: the key is that you need to set In your app's entry file, this just have the assignment before anything else: // src/index.js
__webpack_public_path__ = window.hashwall_asset_path;
require('./rest-of-your-app'); Note that Webpack will transform any |
@developit I'm also facing a similar problem. I'm publishing a library which internally uses a Sharedworker. When bundling this, the sdk.js, and my worker.js are generated. The problem is when the client imports sdk.js, it's part of it's vendor bundle. However worker file is not on the clients public path. This is the code that gets generated by the plugin:
The generated worker file is not available in the publicPath of the client. Not sure how this can be handled. @developit any thoughts on how to handle this? |
@skmvasu what do you have Are you setting |
@developit. I've not set the publicPath inthe webpack outputs. No haven't overriden the This is my build folder structure:
I'm guessing that, copying the generated worker code manually to Please let me know if this make sense. Will give it a try on Monday and update here. |
Ah - I didn't realize this was a module you were distributing via npm. Honestly there's no consensus on Workers should be published to npm, I'm not sure this plugin or any other could provide a solution that works in more than a handful of cases. |
Makes sense. Thanks for taking a look :) We're exploring a few options. Will update if something works. |
@skmvasu just happened upon your reply here and wanted to point you at an npm module myself and Guy Bedford recently released that we hope may offer a fix for distributing Worker-based libraries to npm: |
@developit this is wonderful. I'll check this out this week and see if this works for us. |
I got the same issue when using CDN. Web App is running at http://localhost:3000. It loads JS files from the CDN at http://localhost:4000. The SharedWorker is blocked because it is not same origin:
I'd like to request the feature for dynamic webpack public path. If For example: // webpack.config.js
publicPath: 'http://localhost:4000',
plugins: [
new WorkerPlugin({
sharedWorker: true,
globalObject: 'window',
publicPath: 'http://localhost:3000'
})
] |
According to the webpack docs, you can configure a dynamic public path for output files (like the web worker file) at runtime by adding
__webpack_public_path__ = myRuntimePublicPath;
to the top of your entry. However, this plugin generates a one-line entrye.exports = __webpack_public_path__ + "rustworker.worker.js"
.It would be great if there were some configuration option for this plugin to allow adding the runtime public path override line to the generated entry.
The text was updated successfully, but these errors were encountered: