Bug 1291049 - add webpack loader to rewrite this.browserRequire as require draft
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 22 Nov 2016 19:11:40 +0100
changeset 442573 e32296a6153b
parent 442572 7c4f34770fbc
child 537827 a4e0b8844e33
push id36740
push userjdescottes@mozilla.com
push dateTue, 22 Nov 2016 20:25:49 +0000
bugs1291049
milestone53.0a1
Bug 1291049 - add webpack loader to rewrite this.browserRequire as require MozReview-Commit-ID: 6FydiwZMiYl
devtools/client/inspector/inspector.js.rej
devtools/client/inspector/webpack.config.js
devtools/client/webpack/rewrite-browser-require.js
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/inspector.js.rej
@@ -0,0 +1,11 @@
+--- inspector.js
++++ inspector.js
+@@ -576,7 +568,7 @@
+         defaultTab == "layoutview"
+       );
+ 
+-      const {LayoutView} = this.browserRequire("devtools/client/inspector/layout/layout");
++      const {LayoutView} = require("devtools/client/inspector/layout/layout");
+       this.layoutview = new LayoutView(this, this.panelWin);
+     }
+ 
--- a/devtools/client/inspector/webpack.config.js
+++ b/devtools/client/inspector/webpack.config.js
@@ -30,17 +30,22 @@ module.exports = envConfig => {
       // Warn for every expression in require
       wrappedContextCritical: true,
 
       loaders: [
         {
           test: /event-emitter/,
           exclude: /node_modules/,
           loaders: [path.join(__dirname, "../webpack/rewrite-event-emitter")],
-        },
+        }, {
+          // Replace all references to this.browserRequire() by require() in
+          // client/inspector/
+          test: /client\/inspector\/.*\.js$/,
+          loaders: [path.join(__dirname, "../webpack/rewrite-browser-require")],
+        }
       ]
     },
     resolveLoader: {
       root: [
         path.resolve("./node_modules"),
         path.resolve("../webpack"),
       ]
     },
new file mode 100644
--- /dev/null
+++ b/devtools/client/webpack/rewrite-browser-require.js
@@ -0,0 +1,6 @@
+"use strict";
+
+module.exports = function (content) {
+  this.cacheable && this.cacheable();
+  return content.replace(/this\.browserRequire\(/g, "require(");
+};