forked from nolanlawson/emoji-picker-element
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
105 lines (96 loc) · 2.55 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
import cjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import mainSvelte from 'rollup-plugin-svelte'
import hotSvelte from 'rollup-plugin-svelte-hot'
import preprocess from 'svelte-preprocess'
import analyze from 'rollup-plugin-analyzer'
import cssnano from 'cssnano'
const dev = process.env.NODE_ENV !== 'production'
const svelte = dev ? hotSvelte : mainSvelte
const preprocessConfig = preprocess({
scss: true,
postcss: {
plugins: [
cssnano({
preset: 'default'
})
]
}
})
const origMarkup = preprocessConfig.markup
// minify the HTML by removing extra whitespace
// TODO: this is fragile, but it also results in a lot of bundlesize savings. let's find a better solution
preprocessConfig.markup = async function () {
const res = await origMarkup.apply(this, arguments)
// remove whitespace
res.code = res.code.replace(/([>}])\s+([<{])/sg, '$1$2')
// remove data-testid (only used for testing-library)
res.code = res.code.replace(/data-testid=".*?"/g, '')
return res
}
// Build Database.test.js and Picker.js as separate modules at build times so that they are properly tree-shakeable.
// Most of this has to happen because customElements.define() has side effects
const baseConfig = {
plugins: [
resolve(),
cjs(),
replace({
'process.env.NODE_ENV': dev ? '"development"' : '"production"',
'process.env.PERF': !!process.env.PERF
}),
replace({
'\'../database/Database.js\'': '\'./database.js\'',
delimiters: ['', '']
}),
svelte({
css: true,
customElement: true,
dev,
preprocess: preprocessConfig
}),
!dev && analyze({ summaryOnly: true })
],
external: [
'./database.js',
'../database/Database.js'
]
}
const entryPoints = [
{
input: './src/picker/PickerElement.js',
output: './picker.js'
},
{
input: './src/database/Database.js',
output: './database.js'
},
{
input: './src/trimEmojiData.js',
output: './trimEmojiData.js'
},
{
input: './src/trimEmojiData.js',
output: './trimEmojiData.cjs',
format: 'cjs'
},
{
input: './src/picker/PickerElement.js',
output: './svelte.js',
external: ['svelte', 'svelte/internal']
}
]
export default entryPoints.map(({ input, output, format = 'es', external = [] }) => {
const res = {
...baseConfig,
input,
output: {
format,
file: output,
sourcemap: dev,
exports: 'auto'
}
}
res.external = [...res.external, ...external]
return res
})