diff --git a/bindings/python/.gitignore b/bindings/python/.gitignore index fe3f0184b26..947cb05a54b 100644 --- a/bindings/python/.gitignore +++ b/bindings/python/.gitignore @@ -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 diff --git a/bindings/python/pydeck/dependency_managers/__init__.py b/bindings/python/pydeck/dependency_managers/__init__.py index 2364b04b164..789112483f1 100644 --- a/bindings/python/pydeck/dependency_managers/__init__.py +++ b/bindings/python/pydeck/dependency_managers/__init__.py @@ -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') diff --git a/bindings/python/pydeck/setup.py b/bindings/python/pydeck/setup.py index 90427b1000f..56a34847035 100644 --- a/bindings/python/pydeck/setup.py +++ b/bindings/python/pydeck/setup.py @@ -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 = [] @@ -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: @@ -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"]), diff --git a/modules/jupyter-widget/package.json b/modules/jupyter-widget/package.json index 8cd76baacc7..553ff36fba6 100644 --- a/modules/jupyter-widget/package.json +++ b/modules/jupyter-widget/package.json @@ -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" ], diff --git a/modules/jupyter-widget/src/index.js b/modules/jupyter-widget/src/index.js index bbbb38e3a41..9598b6c19a2 100644 --- a/modules/jupyter-widget/src/index.js +++ b/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'; diff --git a/modules/jupyter-widget/src/nb_extension.js b/modules/jupyter-widget/src/nb_extension.js deleted file mode 100644 index 8264a856fd9..00000000000 --- a/modules/jupyter-widget/src/nb_extension.js +++ /dev/null @@ -1,17 +0,0 @@ -/* 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'); -window.__webpack_public_path__ = `${dataBaseUrl}nbextensions/pydeck/nb_extension`; - -export {MODULE_VERSION, MODULE_NAME, DeckGLModel, DeckGLView} from './index'; diff --git a/modules/jupyter-widget/webpack.config.js b/modules/jupyter-widget/webpack.config.js index 04e096f529a..7112ef8bd0e 100644 --- a/modules/jupyter-widget/webpack.config.js +++ b/modules/jupyter-widget/webpack.config.js @@ -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 * @@ -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() + ] +};