forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
82 lines (69 loc) · 2.74 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
/* 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 path = require("path");
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(
isProduction ? "src/main.js" : "src/main.development.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");
} else {
webpackConfig.entry.debugger = getEntry("src/main.development.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";
extra.excludeMap = mozillaCentralMappings;
extra.recordsPath = "bin/module-manifest.json";
}
module.exports = toolbox.toolboxConfig(webpackConfig, envConfig, extra);