Browse Source

Merge pull request #8845 from goanpeca/fix/public-path

PR: Add slash to publicPath
Steven Silvester 4 năm trước cách đây
mục cha
commit
4362c77662
2 tập tin đã thay đổi với 39 bổ sung2 xóa
  1. 37 0
      dev_mode/publicpath.js
  2. 2 2
      dev_mode/webpack.config.js

+ 37 - 0
dev_mode/publicpath.js

@@ -0,0 +1,37 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+// We dynamically set the webpack public path based on the page config
+// settings from the JupyterLab app. We copy some of the pageconfig parsing
+// logic in @jupyterlab/coreutils below, since this must run before any other
+// files are loaded (including @jupyterlab/coreutils).
+
+/**
+ * Get global configuration data for the Jupyter application.
+ *
+ * @param name - The name of the configuration option.
+ *
+ * @returns The config value or an empty string if not found.
+ *
+ * #### Notes
+ * All values are treated as strings.
+ * For browser based applications, it is assumed that the page HTML
+ * includes a script tag with the id `jupyter-config-data` containing the
+ * configuration as valid JSON.  In order to support the classic Notebook,
+ * we fall back on checking for `body` data of the given `name`.
+ */
+function getOption(name) {
+  let configData = Object.create(null);
+  // Use script tag if available.
+  if (typeof document !== 'undefined' && document) {
+    const el = document.getElementById('jupyter-config-data');
+
+    if (el) {
+      configData = JSON.parse(el.textContent || '{}');
+    }
+  }
+  return configData[name] || '';
+}
+
+// eslint-disable-next-line no-undef
+__webpack_public_path__ = getOption('fullStaticUrl') + '/';

+ 2 - 2
dev_mode/webpack.config.js

@@ -218,11 +218,11 @@ module.exports = [
   merge(baseConfig, {
     mode: 'development',
     entry: {
-      main: ['whatwg-fetch', entryPoint]
+      main: ['./publicpath', 'whatwg-fetch', entryPoint]
     },
     output: {
       path: plib.resolve(buildDir),
-      publicPath: 'static/lab/',
+      publicPath: '{{page_config.fullStaticUrl}}/',
       filename: '[name].[chunkhash].js'
     },
     optimization: {