This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
70 lines (64 loc) · 1.71 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
import typescript from '@rollup/plugin-typescript'
import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import { nodeResolve } from '@rollup/plugin-node-resolve'
let browser_
switch (process.env.BROWSER) {
case undefined:
console.warn(
'\x1b[33mBrowser is not set so fallback to bundle for Google CHrome.',
'Set BROWSER to fix this problem.\x1b[0m'
)
browser_ = 'browser'
break
case 'chrome':
console.warn('\x1b[33mBundling for Google Chrome.\x1b[0m')
browser_ = 'chrome'
break
case 'firefox':
console.warn('\x1b[33mBundling for Mozilla Firefox.\x1b[0m')
browser_ = 'browser'
break
default:
console.warn('\x1b[33mUnknown browser so fallback to bundle for Google Chrome.\x1b[0m')
browser_ = 'chrome'
break
}
const nodeResolveOptions = { browser: true, modulesOnly: true }
const replaceOptions = {
values: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
'__storage__': `${browser_}.storage`,
'__i18n__': `${browser_}.i18n`
},
preventAssignment: true
}
const terserOptions = {
ecma: '2022',
module: true,
mangle: true
}
function getPlugins() {
const ret = [replace(replaceOptions), typescript(), nodeResolve(nodeResolveOptions)]
if (process.env.NODE_ENV === 'production') {
ret.push(terser(terserOptions))
}
return ret
}
const popupConfig = {
input: 'src/scripts/popup.ts',
output: {
dir: 'dist/scripts',
format: 'esm'
},
plugins: getPlugins()
}
const contentScriptConfig = {
input: 'src/scripts/content-script.ts',
output: {
dir: 'dist/scripts',
format: 'esm'
},
plugins: getPlugins()
}
export default [popupConfig, contentScriptConfig]