-
Notifications
You must be signed in to change notification settings - Fork 72
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
Automatically set public path #103
Conversation
The 'auto' setting should automatically choose the correct public path, depending on where the js file was loaded from. This removes the difference between the classic notebook extension bundle and the CDN bundle, so we also consolidated the two webpack targets.
This means the files should be able to be hosted on any CDN. Also update the webpack image loaders to use the new asset/resource type. See also jupyter-widgets/ipywidgets#3464 and jupyter-widgets/widget-cookiecutter#103
It seems that the auto public path logic in webpack does not work for AMD modules, since document.currentScript only works when the script is initially executed, not in a callback. In the cases where we know we are compiling to an AMD module, we can use the requirejs magic 'module' dependency to get the url of the file, and from that do our own auto public path magic. We encapsulate this auto public path setting into its own file so that it does not intrude on user code, and is only used when we know in the webpack config that we are compiling to an AMD module.
It seems that the auto public path logic in webpack does not work for AMD modules, since document.currentScript only works when the script is initially executed, not in a callback. In the cases where we know we are compiling to an AMD module, we can use the requirejs magic 'module' dependency to get the url of the file, and from that do our own auto public path magic. We encapsulate this auto public path setting into its own file so that it does not intrude on user code, and is only used when we know in the webpack config that we are compiling to an AMD module. See also jupyter-widgets/widget-cookiecutter#103
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are both bundles the same now? If so, why do we need to create it twice? For uploading to npm?
Yes, they need to go two different places: the python package for the classic notebook extension, and the npm dist folder for CDN. You're right that we could just create the bundle once and then copy the bundle and other associated files to the other place. It's easier and simpler configuration to have webpack generate it twice, though. |
I don't think webpack can do that out of the box btw (googled that a few days ago), it probably requires some extra 'post' script. |
I think I've used https://webpack.js.org/plugins/copy-webpack-plugin/ before for copying files. |
This is yet another attempt to automatically set the public path, this time using the requirejs magic 'module' dependency. This removes the need to hardcode public paths when compiling to AMD modules, and makes it possible to host the AMD module on any server (and does not hardcode the CDN).
This removes the difference between the classic notebook extension bundle and the CDN bundle, so we also consolidated the two webpack targets.