-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.chrome.mjs
108 lines (98 loc) · 3.66 KB
/
rollup.config.chrome.mjs
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
/*
Copyright 2024 Chris Wheeler
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// https://rollupjs.org/
import copy from 'rollup-plugin-copy'; // https://www.npmjs.com/package/rollup-plugin-copy
import del from 'rollup-plugin-delete'; // https://www.npmjs.com/package/rollup-plugin-delete
// This is a Rollup configuration file for building the Chrome extension. It first
// copies all the necessary files from `src` to the `chrome` directory, then replaces
// all imports with the code the imports correspond to. Lastly, it deletes all files in
// the `chrome` directory that were imported into other files there and are no longer
// needed.
//
// Each time this runs, any existing files with the same names as those copied are
// overwritten.
export default [
{
input: 'chrome/background.js',
output: {
file: 'chrome/background.js',
format: 'iife', // immediately-invoked function expression
},
plugins: [
copy({
targets: [
{
src: [
// Copy everything from `src` to `chrome` except the
// browserSpecific.js that is for testing.
'src/*',
'!src/browserSpecific.js',
],
dest: 'chrome',
},
],
hook: 'buildStart', // run the copy before the build starts
}),
]
},
{
input: 'chrome/content.js',
output: {
file: 'chrome/content.js',
format: 'iife', // immediately-invoked function expression
},
},
{
input: 'chrome/popup.js',
output: {
file: 'chrome/popup.js',
format: 'iife', // immediately-invoked function expression
},
},
{
input: 'chrome/sidebar.js',
output: {
file: 'chrome/sidebar.js',
format: 'iife', // immediately-invoked function expression
},
},
{
input: 'chrome/settings.js',
output: {
file: 'chrome/settings.js',
format: 'iife', // immediately-invoked function expression
},
plugins: [
del({
// Delete all files in the `chrome` directory that were imported into
// other files there and are no longer needed.
targets: [
'chrome/*', // delete all files except the ones below
'!chrome/images',
'!chrome/manifest.json',
'!chrome/**/*.html',
'!chrome/**/*.css',
'!chrome/browserSpecific.js',
'!chrome/background.js',
'!chrome/content.js',
'!chrome/popup.js',
'!chrome/sidebar.js',
'!chrome/settings.js',
'!chrome/text-fragment-utils.js',
'!chrome/fragment-generation-utils.js',
],
hook: 'buildEnd', // run the delete after the build ends
})
]
}
];