浏览代码

Custom webpack config as opt-in for federated extensions

Jeremy Tuloup 4 年之前
父节点
当前提交
294c997442
共有 2 个文件被更改,包括 18 次插入5 次删除
  1. 6 0
      builder/metadata_schema.json
  2. 12 5
      builder/src/extensionConfig.ts

+ 6 - 0
builder/metadata_schema.json

@@ -91,6 +91,12 @@
       "$ref": "#/definitions/relativePath",
       "default": "static"
     },
+    "webpackConfig": {
+      "title": "Custom Webpack config",
+      "description": "The relative path to a custom webpack config",
+      "$ref": "#/definitions/relativePath",
+      "default": null
+    },
     "sharedPackages": {
       "description": "Modules that should be shared in the share scope. When provided, property names are used to match requested modules in this compilation.",
       "ref": "#/definitions/sharedObject"

+ 12 - 5
builder/src/extensionConfig.ts

@@ -194,10 +194,17 @@ function generateConfig({
     }
   }
 
-  const customConfigPath = path.join(packagePath, 'webpack.config.js');
-  let customWebpackConfig = {};
-  if (fs.existsSync(customConfigPath)) {
-    customWebpackConfig = require(customConfigPath);
+  // Allow custom webpack config
+  let webpackConfigPath = data.jupyterlab['webpackConfig'];
+  let webpackConfig = {};
+
+  // Use the custom webpack config only if the path to the config
+  // is specified in package.json (opt-in)
+  if (webpackConfigPath) {
+    webpackConfigPath = path.join(packagePath, webpackConfigPath);
+    if (fs.existsSync(webpackConfigPath)) {
+      webpackConfig = require(webpackConfigPath);
+    }
   }
   const config = [
     merge(
@@ -228,7 +235,7 @@ function generateConfig({
           new CleanupPlugin()
         ]
       },
-      customWebpackConfig
+      webpackConfig
     )
   ].concat(extras);