Skip to content

Commit c84791d

Browse files
authored
Merge pull request #398 from vidartf/publicpath
Update public path logic
2 parents 6102f0c + fa869a4 commit c84791d

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

js/amd-public-path.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// In an AMD module, we set the public path using the magic requirejs 'module' dependency
2+
// See https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#module
3+
// Since 'module' is a requirejs magic module, we must include 'module' in the webpack externals configuration.
4+
var module = require('module');
5+
var url = new URL(module.uri, document.location);
6+
// Using lastIndexOf('/')+1 gives us the empty string if there is no '/', so pathname becomes '/'
7+
url.pathname = url.pathname.slice(0,url.pathname.lastIndexOf('/')+1);
8+
__webpack_public_path__ = `${url.origin}${url.pathname}`;

js/src/extension.js

-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
// Entry point for the notebook bundle containing custom model definitions.
2-
//
3-
// Setup notebook base URL
4-
//
5-
// Some static assets may be required by the custom widget javascript. The base
6-
// url for the notebook is not known at build time and is therefore computed
7-
// dynamically.
8-
__webpack_public_path__ = document.querySelector('body').getAttribute('data-base-url') + 'nbextensions/jupyter-threejs/';
9-
102

113
// Configure requirejs
124
if (window.requirejs) {

js/webpack.config.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path');
22

3-
const externals = ['@jupyter-widgets/base', 'three'];
3+
const externals = ['@jupyter-widgets/base', 'three', 'module'];
44

55
module.exports = [
66
{
@@ -17,11 +17,12 @@ module.exports = [
1717
},
1818
{
1919
// jupyter-threejs bundle for the notebook
20-
entry: './src/index.js',
20+
entry: ['./amd-public-path.js', './src/index.js'],
2121
output: {
2222
filename: 'index.js',
2323
path: path.resolve(__dirname, '..', 'pythreejs', 'static'),
24-
libraryTarget: 'amd'
24+
libraryTarget: 'amd',
25+
publicPath: '', // Set in amd-public-path.js
2526
},
2627
devtool: 'source-map',
2728
externals: externals,
@@ -32,14 +33,15 @@ module.exports = [
3233
},
3334
{
3435
// embeddable jupyter-threejs bundle (e.g. for docs)
35-
entry: './src/index.js',
36+
entry: ['./amd-public-path.js', './src/index.js'],
3637
output: {
3738
filename: 'index.js',
3839
path: path.resolve(__dirname, 'dist'),
3940
library: 'jupyter-threejs',
40-
libraryTarget: 'amd'
41+
libraryTarget: 'amd',
42+
publicPath: '', // Set in amd-public-path.js
4143
},
42-
externals: ['@jupyter-widgets/base'],
44+
externals: ['@jupyter-widgets/base', 'module'],
4345
resolve: {
4446
extensions: [ '.autogen.js', '.js' ]
4547
},

0 commit comments

Comments
 (0)