forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
98 lines (81 loc) · 3.13 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
const toolbox = require("devtools-launchpad/index");
const sourceMapAssets = require("devtools-source-map/assets");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const getConfig = require("./bin/getConfig");
const mozillaCentralMappings = require("./configs/mozilla-central-mappings");
const { NormalModuleReplacementPlugin } = require("webpack");
const path = require("path");
var Visualizer = require("webpack-visualizer-plugin");
const ObjectRestSpreadPlugin = require("@sucrase/webpack-object-rest-spread-plugin");
const isProduction = process.env.NODE_ENV === "production";
/*
* 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(__dirname, filename)];
}
const webpackConfig = {
entry: {
// We always generate the debugger bundle, but we will only copy the CSS
// artifact over to mozilla-central.
debugger: getEntry("src/main.js"),
"parser-worker": getEntry("src/workers/parser/worker.js"),
"pretty-print-worker": getEntry("src/workers/pretty-print/worker.js"),
"search-worker": getEntry("src/workers/search/worker.js"),
"source-map-worker": getEntry("packages/devtools-source-map/src/worker.js"),
"source-map-index": getEntry("packages/devtools-source-map/src/index.js")
},
output: {
path: path.join(__dirname, "assets/build"),
filename: "[name].js",
publicPath: "/assets/build"
},
plugins: [
new CopyWebpackPlugin(
Object.entries(sourceMapAssets).map(([name, filePath]) => ({
from: filePath,
to: `source-map-worker-assets/${name}`
}))
)
]
};
if (isProduction) {
// In the firefox panel, build the vendored dependencies as a bundle instead,
// the other debugger modules will be transpiled to a format that is
// compatible with the DevTools Loader.
webpackConfig.entry.vendors = getEntry("src/vendors.js");
webpackConfig.entry.reps = getEntry("packages/devtools-reps/src/index.js");
}
const envConfig = getConfig();
const extra = {
babelIncludes: ["react-aria-components"]
};
webpackConfig.plugins.push(new ObjectRestSpreadPlugin());
if (!isProduction) {
webpackConfig.module = webpackConfig.module || {};
webpackConfig.module.rules = webpackConfig.module.rules || [];
} else {
webpackConfig.output.libraryTarget = "umd";
if (process.env.vis) {
const viz = new Visualizer({
filename: "webpack-stats.html"
});
webpackConfig.plugins.push(viz);
}
const mappings = [
[/\.\/mocha/, "./mochitest"],
[/\.\.\/utils\/mocha/, "../utils/mochitest"],
[/\.\/utils\/mocha/, "./utils/mochitest"],
[/\.\/percy-stub/, "./percy-webpack"]
];
extra.excludeMap = mozillaCentralMappings;
mappings.forEach(([regex, res]) => {
webpackConfig.plugins.push(new NormalModuleReplacementPlugin(regex, res));
});
}
module.exports = toolbox.toolboxConfig(webpackConfig, envConfig, extra);