forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
79 lines (67 loc) · 2.3 KB
/
webpack.config.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 toolbox = require("./node_modules/devtools-launchpad/index");
const getConfig = require("./bin/getConfig");
const { isDevelopment, isFirefoxPanel } = require("devtools-config");
const { NormalModuleReplacementPlugin } = require("webpack");
const path = require("path");
const projectPath = path.join(__dirname, "src");
/*
* builds a path that's relative to the project path
* returns an array so that we can prepend
* hot-module-reloading in local development
*/
function getEntry(filename) {
return [path.join(projectPath, filename)];
}
let webpackConfig = {
entry: {
debugger: getEntry("main.js"),
"parser-worker": getEntry("utils/parser/worker.js"),
"pretty-print-worker": getEntry("utils/pretty-print/worker.js"),
"integration-tests": getEntry("test/integration/tests.js")
},
output: {
path: path.join(__dirname, "assets/build"),
filename: "[name].js",
publicPath: "/assets/build",
libraryTarget: "umd"
},
resolve: {
alias: {
"react-dom": "react-dom/dist/react-dom"
}
},
module: {
// Ignore the prebuilt mocha lib file.
noParse: /mocha\/mocha\.js/i
}
};
function buildConfig(envConfig) {
if (isDevelopment()) {
webpackConfig.plugins = [];
} else {
webpackConfig.output.libraryTarget = "umd";
webpackConfig.plugins = [];
const mappings = [
[/\.\/mocha/, "./mochitest"],
[/\.\.\/utils\/mocha/, "../utils/mochitest"],
[/\.\/utils\/mocha/, "./utils/mochitest"],
[/\.\/percy-stub/, "./percy-webpack"]
];
mappings.forEach(([regex, res]) => {
webpackConfig.plugins.push(new NormalModuleReplacementPlugin(regex, res));
});
}
// TODO: It would be nice to stop bundling `devtools-source-map` entirely for
// the Firefox panel, but at the moment we still use `isOriginalId` from a
// required copy of the module, instead of using the one from the toolbox.
if (!isFirefoxPanel()) {
// When used as a Firefox panel, the toolbox supplies its own source map
// service and worker, so we only need to build this when running in a tab.
webpackConfig.entry["source-map-worker"] = getEntry(
"../node_modules/devtools-source-map/src/worker.js"
);
}
return toolbox.toolboxConfig(webpackConfig, envConfig);
}
const envConfig = getConfig();
module.exports = buildConfig(envConfig);