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

Automatically set public path #103

Merged
merged 3 commits into from
Aug 8, 2022
Merged

Conversation

jasongrout
Copy link
Member

@jasongrout jasongrout commented Jun 2, 2022

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.

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.
jasongrout added a commit to jasongrout/ipyleaflet that referenced this pull request Jun 2, 2022
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
@jasongrout jasongrout changed the title Default publicPath to 'auto' Automatically set public path Jun 2, 2022
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.
jasongrout added a commit to jasongrout/ipyleaflet that referenced this pull request Jun 2, 2022
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
@jasongrout jasongrout requested a review from ibdafna July 19, 2022 17:29
Copy link
Member

@ibdafna ibdafna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ibdafna ibdafna merged commit 63c32be into jupyter-widgets:master Aug 8, 2022
Copy link
Member

@maartenbreddels maartenbreddels left a 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?

@jasongrout
Copy link
Member Author

jasongrout commented Aug 17, 2022

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.

@maartenbreddels
Copy link
Member

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.

@jasongrout
Copy link
Member Author

I think I've used https://webpack.js.org/plugins/copy-webpack-plugin/ before for copying files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants