Skip to content

Commit

Permalink
[jupyter-widget] use only one endpoint (#3493)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Aug 27, 2019
1 parent 416544f commit 259bedb
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 113 deletions.
8 changes: 2 additions & 6 deletions bindings/python/.gitignore
Expand Up @@ -149,11 +149,7 @@ $RECYCLE.BIN/
**/coverage/

# Cut JS files created in build process
**/pydeck/nbextension/static/nb_extension.js
**/pydeck/nbextension/static/nb_extension.js.map

# Cut JS files created in build process
**/pydeck/nbextension/static/nb_extension.js
**/pydeck/nbextension/static/nb_extension.js.map
**/pydeck/nbextension/static/index.js
**/pydeck/nbextension/static/index.js.map
**/pydeck/nbextension/static/extensionRequires.js
**/pydeck/io/templates/requirejs_dependencies.json
2 changes: 1 addition & 1 deletion bindings/python/pydeck/dependency_managers/__init__.py
Expand Up @@ -53,7 +53,7 @@ def create_notebook_requirejs(dependencies, base_path, setup_environment='develo
# Notebook using the JS bundle built from webpack command in @deck.gl/jupyter-widget
# The notebook dependency manager will be written to ./pydeck/nbextension/static/extensionRequires.js
# If this changes, ./pydeck/nbextension/__init__.py must also change
dependencies['map']['*']['@deck.gl/jupyter-widget'] = 'nbextensions/pydeck/nb_extension'
dependencies['map']['*']['@deck.gl/jupyter-widget'] = 'nbextensions/pydeck/index'
del dependencies['paths']['nbextension/pydeck']
else:
raise Exception('Unrecognized setup environment')
Expand Down
12 changes: 6 additions & 6 deletions bindings/python/pydeck/setup.py
Expand Up @@ -78,8 +78,8 @@ class FrontendBuild(Command):

# Files to copy into the Python side of the widget
target_files = [
os.path.join(here, "pydeck", "nbextension", "static", "nb_extension.js"),
os.path.join(here, "pydeck", "nbextension", "static", "nb_extension.js.map"),
os.path.join(here, "pydeck", "nbextension", "static", "index.js"),
os.path.join(here, "pydeck", "nbextension", "static", "index.js.map"),
]

user_options = []
Expand Down Expand Up @@ -111,8 +111,8 @@ def copy_frontend_build(self):
Overwrites destination files"""
js_dist_dir = os.path.join(widget_dir, "dist")
js_files = [
os.path.join(js_dist_dir, "nb_extension.js"),
os.path.join(js_dist_dir, "nb_extension.js.map"),
os.path.join(js_dist_dir, "index.js"),
os.path.join(js_dist_dir, "index.js.map"),
]
static_folder = os.path.join(here, "pydeck", "nbextension", "static")
for js_file in js_files:
Expand Down Expand Up @@ -240,8 +240,8 @@ def load_requirejs_dependencies():
"share/jupyter/nbextensions/pydeck",
[
"pydeck/nbextension/static/extensionRequires.js",
"pydeck/nbextension/static/nb_extension.js",
"pydeck/nbextension/static/nb_extension.js.map",
"pydeck/nbextension/static/index.js",
"pydeck/nbextension/static/index.js.map",
],
),
("etc/jupyter/nbconfig/notebook.d", ["pydeck.json"]),
Expand Down
7 changes: 3 additions & 4 deletions modules/jupyter-widget/package.json
Expand Up @@ -14,11 +14,10 @@
"type": "git",
"url": "https://github.com/uber/deck.gl.git"
},
"main": "dist/es5/index.js",
"module": "dist/esm/index.js",
"esnext": "dist/es6/index.js",
"main": "dist/index.js",
"files": [
"dist",
"dist/index.js",
"dist/index.js.map",
"src",
"README.md"
],
Expand Down
18 changes: 17 additions & 1 deletion modules/jupyter-widget/src/index.js
@@ -1,4 +1,20 @@
// Copyright (c) Uber Technologies Inc.
/* global window, document */
// See https://github.com/jupyter-widgets/widget-ts-cookiecutter/blob/master/%7B%7Bcookiecutter.github_project_name%7D%7D/src/extension.ts
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

// Entry point for the notebook bundle containing custom model definitions.
//
// Setup notebook base URL
//
// Some static assets may be required by the custom widget javascript. The base
// url for the notebook is not known at build time and is therefore computed
// dynamically.
//
const dataBaseUrl = document.querySelector('body').getAttribute('data-base-url');
if (dataBaseUrl) {
window.__webpack_public_path__ = `${dataBaseUrl}nbextensions/pydeck/nb_extension`;
}

export {MODULE_VERSION, MODULE_NAME} from './version';
export {DeckGLModel, DeckGLView, initDeck} from './widget';
17 changes: 0 additions & 17 deletions modules/jupyter-widget/src/nb_extension.js

This file was deleted.

116 changes: 38 additions & 78 deletions modules/jupyter-widget/webpack.config.js
Expand Up @@ -2,62 +2,7 @@
// https://github.com/jupyter-widgets/widget-ts-cookiecutter/blob/master/%7B%7Bcookiecutter.github_project_name%7D%7D/webpack.config.js
const path = require('path');

const rules = [
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(jpg|png|gif|svg)$/,
use: ['file-loader']
},
{
// Compile ES2015 using babel
test: /\.js$/,
loader: 'babel-loader',
include: /src/,
options: {
presets: [['@babel/preset-env', {forceAllTransforms: true}]],
// all of the helpers will reference the module @babel/runtime to avoid duplication
// across the compiled output.
plugins: [
'@babel/transform-runtime',
'inline-webgl-constants',
['remove-glsl-comments', {patterns: ['**/*.glsl.js']}]
]
}
}
];

const resolve = {
extensions: ['.webpack.js', '.web.js', '.js']
};

// Packages that shouldn't be bundled but loaded at runtime
const externals = ['@jupyter-widgets/base'];

module.exports = [
{
/**
* Notebook extension
*
* This bundle only contains the part of the JavaScript that is run on load of
* the notebook.
*/
entry: './src/nb_extension.js',
output: {
filename: 'nb_extension.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'amd'
},
devtool: 'source-map',
module: {
rules
},
externals,
resolve
},

module.exports = {
/**
* Embeddable @deck.gl/jupyter-widget bundle
*
Expand All @@ -68,25 +13,40 @@ module.exports = [
* The target bundle is always `dist/index.js`, which is the path required by
* the custom widget embedder.
*/
{
entry: './src/index.js',
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'amd'
},
devtool: 'source-map',
devServer: {
contentBase: path.join(__dirname, 'dist')
},
module: {
rules
},
externals,
plugins: [
// Uncomment for bundle size debug
// new (require('webpack-bundle-analyzer')).BundleAnalyzerPlugin()
],
resolve
}
];
entry: './src/index.js',
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'amd'
},
devtool: 'source-map',
devServer: {
contentBase: path.join(__dirname, 'dist')
},
module: {
rules: [
{
// Compile ES2015 using babel
test: /\.js$/,
loader: 'babel-loader',
include: /src/,
options: {
presets: [['@babel/preset-env', {forceAllTransforms: true}]],
// all of the helpers will reference the module @babel/runtime to avoid duplication
// across the compiled output.
plugins: [
'@babel/transform-runtime',
'inline-webgl-constants',
['remove-glsl-comments', {patterns: ['**/*.glsl.js']}]
]
}
}
]
},
// Packages that shouldn't be bundled but loaded at runtime
externals: ['@jupyter-widgets/base'],
plugins: [
// Uncomment for bundle size debug
// new (require('webpack-bundle-analyzer')).BundleAnalyzerPlugin()
]
};

0 comments on commit 259bedb

Please sign in to comment.