-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
66 lines (62 loc) · 1.66 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
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import htmlTemplate from 'rollup-plugin-generate-html-template';
import copy from 'rollup-plugin-copy';
import del from 'rollup-plugin-delete';
import css from 'rollup-plugin-css-only';
import svelte from 'rollup-plugin-svelte';
import { terser } from 'rollup-plugin-terser';
import sveltePreprocess from 'svelte-preprocess';
const mode = process.env.NODE_ENV || 'development';
const prod = mode === 'production';
const createConfig = (name, useSvelte = false, additionalPlugins = []) => {
return {
input: `src/${name}/index.js`,
output: {
format: 'iife',
file: `dist/${name}.js`,
name,
extend: true,
},
plugins: [
useSvelte &&
svelte({
compilerOptions: {
dev: !prod,
},
preprocess: sveltePreprocess(),
}),
css({ output: `${name}.css` }),
useSvelte &&
htmlTemplate({
template: 'src/index.html',
target: `dist/${name}.html`,
}),
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ['svelte'],
}),
commonjs(),
prod && terser(),
...additionalPlugins,
],
};
};
export default [
createConfig('options', true, [
del({
targets: 'dist/*',
hook: 'buildStart',
}),
copy({
targets: [
{ src: 'src/manifest.json', dest: 'dist/' },
{ src: 'src/assets/', dest: 'dist/' },
],
}),
]),
createConfig('popup', true),
createConfig('content-scripts', true),
createConfig('background'),
];