forked from jupyter-widgets/ipyleaflet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
fd4cb26
commit 122754b
Showing
2 changed files
with
36 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// In an AMD module, we set the public path using the magic requirejs 'module' dependency | ||
// See https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#module | ||
// Since 'module' is a requirejs magic module, we must include 'module' in the webpack externals configuration. | ||
var module = require('module'); | ||
var url = new URL(module.uri, document.location) | ||
// Using lastIndexOf('/')+1 gives us the empty string if there is no '/', so pathname becomes '/' | ||
url.pathname = url.pathname.slice(0,url.pathname.lastIndexOf('/')+1); | ||
__webpack_public_path__ = `${url.origin}${url.pathname}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters