浏览代码

Refactor to allow third party extension loading

Steven Silvester 8 年之前
父节点
当前提交
22cc26cf7c
共有 5 个文件被更改,包括 94 次插入55 次删除
  1. 30 0
      jupyterlab/extensions.js
  2. 1 34
      jupyterlab/index.js
  3. 16 3
      jupyterlab/lab.html
  4. 3 0
      jupyterlab/plugin.js
  5. 44 18
      jupyterlab/webpack.config.js

+ 30 - 0
jupyterlab/extensions.js

@@ -0,0 +1,30 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+module.exports = [
+  require('jupyterlab/lib/about/plugin').aboutExtension,
+  require('jupyterlab/lib/clipboard/plugin').clipboardProvider,
+  require('jupyterlab/lib/commandpalette/plugin').commandPaletteProvider,
+  require('jupyterlab/lib/console/plugin').consoleExtension,
+  require('jupyterlab/lib/console/codemirror/plugin').rendererProvider,
+  require('jupyterlab/lib/csvwidget/plugin').csvHandlerExtension,
+  require('jupyterlab/lib/docregistry/plugin').docRegistryProvider,
+  require('jupyterlab/lib/editorwidget/plugin').editorHandlerProvider,
+  require('jupyterlab/lib/faq/plugin').faqExtension,
+  require('jupyterlab/lib/filebrowser/plugin').fileBrowserProvider,
+  require('jupyterlab/lib/help/plugin').helpHandlerExtension,
+  require('jupyterlab/lib/imagewidget/plugin').imageHandlerExtension,
+  require('jupyterlab/lib/inspector/plugin').inspectorProvider,
+  require('jupyterlab/lib/landing/plugin').landingExtension,
+  require('jupyterlab/lib/leafletwidget/plugin').mapHandlerExtension,
+  require('jupyterlab/lib/main/plugin').mainExtension,
+  require('jupyterlab/lib/mainmenu/plugin').mainMenuProvider,
+  require('jupyterlab/lib/markdownwidget/plugin').markdownHandlerExtension,
+  require('jupyterlab/lib/notebook/plugin').notebookTrackerProvider,
+  require('jupyterlab/lib/notebook/codemirror/plugin').rendererProvider,
+  require('jupyterlab/lib/rendermime/plugin').renderMimeProvider,
+  require('jupyterlab/lib/running/plugin').runningSessionsExtension,
+  require('jupyterlab/lib/services/plugin').servicesProvider,
+  require('jupyterlab/lib/shortcuts/plugin').shortcutsExtension,
+  require('jupyterlab/lib/terminal/plugin').terminalExtension
+];

+ 1 - 34
jupyterlab/index.js

@@ -11,37 +11,4 @@ require('material-design-icons/iconfont/material-icons.css');
 
 require('jupyterlab/lib/default-theme/index.css');
 
-var lab = new JupyterLab();
-
-lab.registerPlugins([
-  require('jupyterlab/lib/about/plugin').aboutExtension,
-  require('jupyterlab/lib/clipboard/plugin').clipboardProvider,
-  require('jupyterlab/lib/commandpalette/plugin').commandPaletteProvider,
-  require('jupyterlab/lib/console/plugin').consoleExtension,
-  require('jupyterlab/lib/console/codemirror/plugin').rendererProvider,
-  require('jupyterlab/lib/csvwidget/plugin').csvHandlerExtension,
-  require('jupyterlab/lib/docregistry/plugin').docRegistryProvider,
-  require('jupyterlab/lib/editorwidget/plugin').editorHandlerProvider,
-  require('jupyterlab/lib/faq/plugin').faqExtension,
-  require('jupyterlab/lib/filebrowser/plugin').fileBrowserProvider,
-  require('jupyterlab/lib/help/plugin').helpHandlerExtension,
-  require('jupyterlab/lib/imagewidget/plugin').imageHandlerExtension,
-  require('jupyterlab/lib/inspector/plugin').inspectorProvider,
-  require('jupyterlab/lib/landing/plugin').landingExtension,
-  require('jupyterlab/lib/leafletwidget/plugin').mapHandlerExtension,
-  require('jupyterlab/lib/main/plugin').mainExtension,
-  require('jupyterlab/lib/mainmenu/plugin').mainMenuProvider,
-  require('jupyterlab/lib/markdownwidget/plugin').markdownHandlerExtension,
-  require('jupyterlab/lib/notebook/plugin').notebookTrackerProvider,
-  require('jupyterlab/lib/notebook/codemirror/plugin').rendererProvider,
-  require('jupyterlab/lib/rendermime/plugin').renderMimeProvider,
-  require('jupyterlab/lib/running/plugin').runningSessionsExtension,
-  require('jupyterlab/lib/services/plugin').servicesProvider,
-  require('jupyterlab/lib/shortcuts/plugin').shortcutsExtension,
-  require('jupyterlab/lib/terminal/plugin').terminalExtension
-
-
-  // require('jupyter-js-widgets-labextension/lib/plugin').widgetManagerExtension,
-]);
-
-lab.start();
+module.exports = new JupyterLab();

+ 16 - 3
jupyterlab/lab.html

@@ -13,7 +13,9 @@ Distributed under the terms of the Modified BSD License.
     {% if mathjax_url %}
     <script type="text/javascript" src="{{mathjax_url}}?config={{mathjax_config}}&amp;delayStartupUntil=configured" charset="utf-8"></script>
     {% endif %}
-    <link href="{{static_prefix}}/jupyterlab.css" rel="stylesheet">
+    <!-- These will get templated by the server (it will look for css files) -->
+    <link href="{{static_prefix}}/main.css" rel="stylesheet">
+    <link href="{{static_prefix}}/extensions.css" rel="stylesheet">
     
 </head>
 
@@ -28,8 +30,19 @@ Distributed under the terms of the Modified BSD License.
 }</script>
 <script src="{{static_prefix}}/loader.bundle.js" type="text/javascript" charset="utf-8"></script>
 <script>
-jupyter.ensure('lab/jupyterlab.bundle.js', function(requireFunc) {
-  requireFunc("jupyterlab-extension@0.1.0/index.js");
+// TODO: add an ensure-all that makes sure all of the bundles are loaded.
+// The template uses ensureAll and then requires the extension points in
+// order.  
+// TODO: create a top-level manifest that has the entry point define name.
+// The template uses those names to assemble the plugins.
+jupyter.ensure('lab/main.bundle.js', function(requireFunc) {
+  jupyter.ensure('lab/extensions.bundle.js', function(requireFunc) {
+    var lab = requireFunc("jupyterlab-extension@0.1.0/index.js");
+    jupyter.lab = lab;
+    var plugins = requireFunc('jupyterlab-extension@0.1.0/extensions.js');
+    lab.registerPlugins(plugins);
+    lab.start();
+  });
 });
 </script>
 </body>

+ 3 - 0
jupyterlab/plugin.js

@@ -22,6 +22,9 @@ function JupyterLabPlugin(options) {
 JupyterLabPlugin.prototype.apply = function(compiler) {
   var pluginName = this.name;
   var publicPath = compiler.options.output.publicPath;
+  if (!publicPath) {
+    throw new Error('Must define a public path');
+  }
   if (!publicPath.endsWith('/')) {
     publicPath += '/';
   }

+ 44 - 18
jupyterlab/webpack.config.js

@@ -11,9 +11,28 @@ var JupyterLabPlugin = require('./plugin');
 console.log('Generating bundles...');
 
 
+var LOADERS = [
+  { test: /\.css$/,
+    loader: ExtractTextPlugin.extract("style-loader", "css-loader", {
+      publicPath: './'
+    })
+  },
+  { test: /\.json$/, loader: 'json-loader' },
+  { test: /\.html$/, loader: 'file-loader' },
+  // jquery-ui loads some images
+  { test: /\.(jpg|png|gif)$/, loader: 'file-loader' },
+  // required to load font-awesome
+  { test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
+  { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
+  { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
+  { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader' },
+  { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=image/svg+xml' }
+];
+
+
 module.exports = [{
   entry: {
-    jupyterlab: './index.js'
+    main: './index.js'
   },
   output: {
     path: __dirname + '/build',
@@ -27,23 +46,7 @@ module.exports = [{
   bail: true,
   devtool: 'source-map',
   module: {
-    loaders: [
-      { test: /\.css$/,
-        loader: ExtractTextPlugin.extract("style-loader", "css-loader", {
-          publicPath: './'
-        })
-      },
-      { test: /\.json$/, loader: 'json-loader' },
-      { test: /\.html$/, loader: 'file-loader' },
-      // jquery-ui loads some images
-      { test: /\.(jpg|png|gif)$/, loader: 'file-loader' },
-      // required to load font-awesome
-      { test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
-      { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
-      { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
-      { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader' },
-      { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=image/svg+xml' }
-    ]
+    loaders: LOADERS
   },
   plugins: [
     new ExtractTextPlugin('[name].css'),
@@ -66,5 +69,28 @@ module.exports = [{
   debug: true,
   bail: true,
   devtool: 'source-map'
+},
+{
+  entry: {
+    extensions: './extensions'
+  },
+  output: {
+    path: __dirname + '/build',
+    filename: '[name].bundle.js',
+    publicPath: './lab/'
+  },
+  node: {
+    fs: 'empty'
+  },
+  debug: true,
+  bail: true,
+  devtool: 'source-map',
+  module: {
+    loaders: LOADERS
+  },
+  plugins: [
+    new ExtractTextPlugin('[name].css'),
+    new JupyterLabPlugin()
+  ],
 }
 ];