forked from ottomated/noft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
64 lines (57 loc) · 1.6 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
import path from 'path';
import { terser } from 'rollup-plugin-terser';
import css from 'rollup-plugin-postcss';
import image from '@rollup/plugin-image';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import {
chromeExtension,
simpleReloader,
} from 'rollup-plugin-chrome-extension';
import { emptyDir } from 'rollup-plugin-empty-dir';
import zip from 'rollup-plugin-zip';
import replace from '@rollup/plugin-replace';
import { readFileSync } from 'fs';
const isProduction = process.env.NODE_ENV === 'production';
const env = Object.fromEntries(
readFileSync('.env', 'utf8')
.split('\n')
.map((l) => {
const [k, v] = l.split('=');
return ['process.env.' + k, JSON.stringify(v)];
})
);
const getConfig = (version) => ({
input: `src/manifest.${version}.ts`,
output: {
dir: 'dist/' + version,
format: 'esm',
chunkFileNames: path.join('chunks', '[name]-[hash].js'),
},
plugins: [
replace({
'process.env.NODE_ENV': isProduction
? JSON.stringify('production')
: JSON.stringify('development'),
...env,
preventAssignment: true,
}),
chromeExtension(),
// Adds a Chrome extension reloader during watch mode
simpleReloader(),
resolve(),
commonjs(),
typescript(),
css(),
image(),
// Empties the output dir before a new build
emptyDir(),
isProduction && terser(),
// Outputs a zip file in ./releases
isProduction && zip({ dir: 'releases/' + version }),
],
});
const configs = [getConfig('v3')];
if (isProduction) configs.push(getConfig('v2'));
export default configs;