Skip to content

Commit b5a2c83

Browse files
Get publicpath in runtime (#58)
* Get publicPath in runtime * Add module to externals
1 parent 6a071e7 commit b5a2c83

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

amd-public-path.js

Lines changed: 8 additions & 0 deletions
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+
import * as module from 'module';
5+
const url = new URL(module.uri, document.location);
6+
7+
url.pathname = url.pathname.slice(0, url.pathname.lastIndexOf('/voila/'));
8+
__webpack_public_path__ = `${url.origin}${url.pathname}/voila/templates/tiledb/static/babylonjs/`;

webpack.config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require('path');
2-
const version = require('./package.json').version;
32

43
// Custom webpack rules
54
const rules = [
@@ -9,7 +8,7 @@ const rules = [
98
];
109

1110
// Packages that shouldn't be bundled but loaded at runtime
12-
const externals = ['@jupyter-widgets/base'];
11+
const externals = ['@jupyter-widgets/base', 'module'];
1312

1413
const resolve = {
1514
// Add '.ts' and '.tsx' as resolvable extensions.
@@ -28,13 +27,13 @@ module.exports = [
2827
* the custom widget embedder.
2928
*/
3029
{
31-
entry: './src/embed.ts',
30+
entry: ['./amd-public-path.js', './src/embed.ts'],
3231
output: {
3332
filename: 'index.js',
3433
path: path.resolve(__dirname, 'dist'),
3534
libraryTarget: 'amd',
3635
library: "@tiledb-inc/pybabylonjs",
37-
publicPath: 'https://unpkg.com/@tiledb-inc/pybabylonjs@' + version + '/dist/'
36+
publicPath: '', // Set in amd-public-path.js
3837
},
3938
devtool: 'source-map',
4039
module: {

0 commit comments

Comments
 (0)