Skip to content

Commit 417ad42

Browse files
authored
add embeddable bundle
I was able to get my custom widget (built using this cookie-ts-cutter) to be embeddable in an exported HTML file and render on NBviewer after making this change. This was referenced in issue #29 and proposed by @jasongrout (there was also an additional change proposed to the package.json, which I'll include an another commit).
1 parent 7e0b1bc commit 417ad42

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

{{cookiecutter.github_project_name}}/webpack.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const rules = [
66

77
// Packages that shouldn't be bundled but loaded at runtime
88
const externals = ['@jupyter-widgets/base', 'three', 'jupyter-threejs'];
9+
var version = require('./package.json').version;
10+
var path = require('path');
911

1012
module.exports = [
1113
{
@@ -46,4 +48,35 @@ module.exports = [
4648
extensions: [".webpack.js", ".web.js", ".ts", ".js"]
4749
},
4850
},
51+
{// Embeddable {{ cookiecutter.npm_package_name }} bundle
52+
//
53+
// This bundle is generally almost identical to the notebook bundle
54+
// containing the custom widget views and models.
55+
//
56+
// The only difference is in the configuration of the webpack public path
57+
// for the static assets.
58+
//
59+
// It will be automatically distributed by unpkg to work with the static
60+
// widget embedder.
61+
//
62+
// The target bundle is always `dist/index.js`, which is the path required
63+
// by the custom widget embedder.
64+
//
65+
entry: './src/index.ts',
66+
output: {
67+
filename: 'index.js',
68+
path: path.resolve(__dirname, 'dist'),
69+
libraryTarget: 'amd',
70+
publicPath: 'https://unpkg.com/{{ cookiecutter.npm_package_name }}@' + version + '/dist/'
71+
},
72+
devtool: 'source-map',
73+
module: {
74+
rules: rules
75+
},
76+
externals: ['@jupyter-widgets/base'],
77+
resolve: {
78+
// Add '.ts' and '.tsx' as resolvable extensions.
79+
extensions: [".webpack.js", ".web.js", ".ts", ".js"]
80+
},
81+
}
4982
];

0 commit comments

Comments
 (0)