forked from firefox-devtools/devtools-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.devtools.js
79 lines (65 loc) · 2.37 KB
/
webpack.config.devtools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const path = require("path");
const webpack = require("webpack");
const { NormalModuleReplacementPlugin } = webpack;
const { DefinePlugin } = webpack;
const nativeMapping = {
react: "devtools/client/shared/vendor/react",
"react-dom": "devtools/client/shared/vendor/react-dom",
"react-dom-factories": "devtools/client/shared/vendor/react-dom-factories",
"prop-types": "devtools/client/shared/vendor/react-prop-types",
lodash: "devtools/client/shared/vendor/lodash"
};
const rootDir = path.join(__dirname, "../..");
const outputPath = process.env.OUTPUT_PATH;
module.exports = (webpackConfig, envConfig, options) => {
if (outputPath) {
webpackConfig.output.path = outputPath;
}
webpackConfig.devtool = false;
webpackConfig.recordsPath = path.join(rootDir, "assets/module-manifest.json");
function externalsTest(context, request, callback) {
let mod = request;
if (mod.match(/.*\/Services$/)) {
callback(null, "Services");
return;
}
// Any matching paths here won't be included in the bundle.
const excludeMap = (options && options.excludeMap) || nativeMapping;
if (excludeMap[mod]) {
const mapping = excludeMap[mod];
if (webpackConfig.externalsRequire) {
// If the tool defines "externalsRequire" in the webpack config, wrap
// all require to external dependencies with a call to the tool's
// externalRequire method.
let reqMethod = webpackConfig.externalsRequire;
callback(null, `var ${reqMethod}("${mapping}")`);
} else {
callback(null, mapping);
}
return;
}
callback();
}
webpackConfig.externals = webpackConfig.externals || [];
webpackConfig.externals.push(externalsTest);
// Remove the existing DefinePlugin so we can override it.
const plugins = webpackConfig.plugins.filter(
p => !(p instanceof DefinePlugin)
);
webpackConfig.plugins = plugins.concat([
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || "production"),
TARGET: JSON.stringify("firefox-panel")
},
"DebuggerConfig": JSON.stringify(envConfig)
})
]);
const mappings = [
[/.\/src\/network-request/, "./src/privileged-network-request"],
];
mappings.forEach(([regex, res]) => {
webpackConfig.plugins.push(new NormalModuleReplacementPlugin(regex, res));
});
return webpackConfig;
};