Bladeren bron

Further streamline down to two configs

Steven Silvester 8 jaren geleden
bovenliggende
commit
fb68be2cf7
3 gewijzigde bestanden met toevoegingen van 24 en 42 verwijderingen
  1. 1 1
      jupyterlab/lab.html
  2. 6 14
      jupyterlab/webpack.config.js
  3. 17 27
      scripts/extension_helpers.js

+ 1 - 1
jupyterlab/lab.html

@@ -31,9 +31,9 @@ Distributed under the terms of the Modified BSD License.
   "notebookPath": "{{notebook_path | urlencode}}"
 }</script>
 
-<script src="{{static_prefix}}/phosphor.bundle.js" type="text/javascript" charset="utf-8"></script>
 <script src="{{static_prefix}}/vendor.bundle.js" type="text/javascript" charset="utf-8"></script>
 <script src="{{static_prefix}}/codemirror.bundle.js" type="text/javascript" charset="utf-8"></script>
+<script src="{{static_prefix}}/phosphor.bundle.js" type="text/javascript" charset="utf-8"></script>
 <script src="{{static_prefix}}/services.bundle.js" type="text/javascript" charset="utf-8"></script>
 <script src="{{static_prefix}}/lab.bundle.js" type="text/javascript" charset="utf-8"></script>
 <script src="{{static_prefix}}/plugins.bundle.js" type="text/javascript" charset="utf-8"></script>

+ 6 - 14
jupyterlab/webpack.config.js

@@ -74,6 +74,7 @@ module.exports = [
   entry: {
     lab: './build/jupyterlab-shim.js',
     services: ['jupyter-js-services'],
+    phosphor: ['./build/phosphor-shim.js'],
     codemirror: helpers.CODEMIRROR_FILES,
     vendor: helpers.VENDOR_FILES
   },
@@ -88,6 +89,11 @@ module.exports = [
   },
   plugins: [
     new ExtractTextPlugin('[name].css'),
+    new webpack.optimize.CommonsChunkPlugin({
+      name: 'phosphor',
+      filename: 'phosphor.bundle.js',
+      chunks: ['lab', 'services']
+    }),
     new webpack.optimize.CommonsChunkPlugin({
       name: 'services',
       filename: 'services.bundle.js',
@@ -104,19 +110,5 @@ module.exports = [
   bail: true,
   devtool: 'source-map',
   externals: helpers.BASE_EXTERNALS
-},
-// Phosphor bundle
-{
-  entry: {
-    phosphor: './build/phosphor-shim.js'
-  },
-  output: {
-      filename: '[name].bundle.js',
-      path: './build',
-      publicPath: './',
-      library: ['jupyter', '[name]']
-  },
-  bail: true,
-  devtool: 'source-map'
 }
 ]

+ 17 - 27
scripts/extension_helpers.js

@@ -62,34 +62,15 @@ codeMirrorPaths = codemirrorPaths.concat(['codemirror', '../lib/codemirror', '..
 
 
 /**
- * The Webpack `externals` config for JupyterLab itself.
+ * The default Webpack `externals` config that should be applied to
+ * extensions of JupyterLab.
  */
-var BASE_EXTERNALS = [
-  function(context, request, callback) {
-    // All phosphor imports get mangled to use the external bundle.
-    var regex = /^phosphor\/lib\/[\w\/]+$/;
-    if(regex.test(request)) {
-        var path = require.resolve(request);
-        var index = path.indexOf('phosphor/lib');
-        path = path.slice(index + 'phosphor/lib/'.length);
-        var lib = 'var jupyter.phosphor["' + path + '"]';
-        return callback(null, lib);
-    }
-    callback();
-  },
+var DEFAULT_EXTERNALS = [
   {
+    'jupyter-js-services': 'jupyter.services',
     'jquery': '$',
     'jquery-ui': '$'
-  }
-];
-
-
-/**
- * The default Webpack `externals` config that should be applied to
- * extensions of JupyterLab.
- */
-var EXTENSION_EXTERNALS = BASE_EXTERNALS.concat([
-  { 'jupyter-js-services': 'jupyter.services' },
+  },
   function(context, request, callback) {
     // JupyterLab imports get mangled to use the external bundle.
     var regex = /^jupyterlab\/lib\/([\w\.\/]+)$/;
@@ -105,6 +86,16 @@ var EXTENSION_EXTERNALS = BASE_EXTERNALS.concat([
       return callback(null, lib);
     }
 
+    // All phosphor imports get mangled to use the external bundle.
+    var regex = /^phosphor\/lib\/[\w\/]+$/;
+    if(regex.test(request)) {
+        var path = require.resolve(request);
+        var index = path.indexOf('phosphor/lib');
+        path = path.slice(index + 'phosphor/lib/'.length);
+        var lib = 'var jupyter.phosphor["' + path + '"]';
+        return callback(null, lib);
+    }
+
     // CodeMirror imports just use the external bundle.
     if (codemirrorPaths.indexOf(request) !== -1) {
       return callback(null, 'var jupyter.CodeMirror');
@@ -112,7 +103,7 @@ var EXTENSION_EXTERNALS = BASE_EXTERNALS.concat([
 
     callback();
   }
-]);
+];
 
 
 // determine whether the package JSON contains a JupyterLab extension
@@ -203,8 +194,7 @@ function upstream_externals(_require) {
 module.exports = {
   upstream_externals: upstream_externals,
   validate_extension: validate_extension,
-  BASE_EXTERNALS: BASE_EXTERNALS,
-  EXTENSION_EXTERNALS: EXTENSION_EXTERNALS,
+  DEFAULT_EXTERNALS: DEFAULT_EXTERNALS,
   CODEMIRROR_FILES: CODEMIRROR_FILES,
   VENDOR_FILES: VENDOR_FILES,
 };