This repository was archived by the owner on Mar 17, 2023. It is now read-only.
generated from mozilla-rally/study-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.config.js
139 lines (131 loc) · 5.05 KB
/
rollup.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* 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/. */
// This is the Rollup configuration for the study template. It is
// part of the build system, and you should not have to modify it.
import commonjs from "@rollup/plugin-commonjs";
import copy from "rollup-plugin-copy";
import replace from "@rollup/plugin-replace";
import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import globby from "globby";
import webScienceRollupPlugin from "@mozilla/web-science/rollup-plugin";
/**
* Helper to detect developer mode.
*
* @param cliArgs the command line arguments.
* @return {Boolean} whether or not developer mode is enabled.
*/
function isDevMode(cliArgs) {
return Boolean(cliArgs["config-enable-developer-mode"]);
}
/**
* Helper to detect emulator mode.
*
* @param cliArgs the command line arguments.
* @return {Boolean} whether or not emulator mode is enabled.
*/
function isEmulatorMode(cliArgs) {
return Boolean(cliArgs["config-enable-emulator-mode"]);
}
export default (cliArgs) => {
// Configuration for the main background script, src/background.js.
// The script will be output to dist/background.js with any module
// dependencies (your own modules or modules from NPM) bundled in.
const rollupConfig = [
{
input: ["src/background.ts"],
output: {
file: "dist/background.js",
sourcemap: (isDevMode(cliArgs) || isEmulatorMode(cliArgs)) ? "inline" : false,
},
plugins: [
replace({
preventAssignment: true,
// In Developer Mode, the study does not submit data and
// gracefully handles communication errors with the Core
// Add-on.
__ENABLE_DEVELOPER_MODE__: isDevMode(cliArgs),
__ENABLE_EMULATOR_MODE__: isEmulatorMode(cliArgs),
}),
webScienceRollupPlugin(),
resolve({
browser: true,
}),
commonjs(),
typescript()
],
},
{
input: "src/background-loader.ts",
output: {
file: "dist/background-loader.js",
sourcemap: (isDevMode(cliArgs) || isEmulatorMode(cliArgs)) ? "inline" : false,
},
plugins: [
replace({
preventAssignment: true,
// In Developer Mode, the study does not submit data and
// gracefully handles communication errors with the Core
// Add-on.
__ENABLE_DEVELOPER_MODE__: isDevMode(cliArgs),
__ENABLE_EMULATOR_MODE__: isEmulatorMode(cliArgs),
}),
webScienceRollupPlugin(),
resolve({
browser: true,
}),
commonjs(),
typescript(),
copy({
targets: [{
src: [
"node_modules/webextension-polyfill/dist/browser-polyfill.min.js",
],
dest: "dist/",
}],
flatten: true,
}),
copy({
targets: [{
src: [
"node_modules/webextension-polyfill/dist/browser-polyfill.min.js.map",
],
dest: "dist/",
}],
flatten: true,
}),
],
}
];
// Configuration for content scripts (src/**/*.content.js) and
// worker scripts (src/**/*.worker.js). These files will be
// output to dist/ with the same relative path they have in
// src/, but with any module dependencies (your own modules or
// modules from npm) bundled in. We provide this configuration
// because content scripts and worker scripts have separate
// execution environments from background scripts, and a
// background script might want to reference the bundled
// scripts (e.g., browser.contentScripts.register() or new
// Worker()).
const scriptPaths = globby.sync([`src/**/*.content.ts`, `src/**/*.worker.ts`]);
for (const scriptPath of scriptPaths) {
rollupConfig.push({
input: scriptPath,
output: {
file: `dist/${scriptPath.slice("src/".length).replace(".ts", ".js")}`,
format: "iife",
sourcemap: (isDevMode(cliArgs) || isEmulatorMode(cliArgs)) ? "inline" : false,
},
plugins: [
webScienceRollupPlugin(),
resolve({
browser: true,
}),
commonjs(),
typescript()
],
});
}
return rollupConfig;
}