2020-05-17 05:36:21 +02:00
|
|
|
import cjs from '@rollup/plugin-commonjs'
|
|
|
|
import resolve from '@rollup/plugin-node-resolve'
|
|
|
|
import replace from '@rollup/plugin-replace'
|
2021-05-31 17:45:59 +02:00
|
|
|
import strip from '@rollup/plugin-strip'
|
2021-06-27 18:25:54 +02:00
|
|
|
import svelte from 'rollup-plugin-svelte'
|
2020-06-15 19:03:07 +02:00
|
|
|
import preprocess from 'svelte-preprocess'
|
2020-06-09 16:09:23 +02:00
|
|
|
import analyze from 'rollup-plugin-analyzer'
|
2023-06-18 21:14:18 +02:00
|
|
|
import { buildStyles } from './bin/buildStyles.js'
|
2020-05-10 04:39:47 +02:00
|
|
|
|
2021-07-02 18:58:05 +02:00
|
|
|
const { NODE_ENV, DEBUG } = process.env
|
2021-05-31 17:45:59 +02:00
|
|
|
const dev = NODE_ENV !== 'production'
|
2020-05-31 18:34:17 +02:00
|
|
|
|
2021-07-11 19:01:21 +02:00
|
|
|
const preprocessConfig = preprocess()
|
2020-06-22 03:26:11 +02:00
|
|
|
|
|
|
|
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)
|
2020-06-25 17:44:54 +02:00
|
|
|
|
|
|
|
// remove whitespace
|
2020-06-22 03:26:11 +02:00
|
|
|
res.code = res.code.replace(/([>}])\s+([<{])/sg, '$1$2')
|
2020-06-25 17:44:54 +02:00
|
|
|
|
2020-06-22 03:26:11 +02:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2020-06-07 04:36:45 +02:00
|
|
|
// Build Database.test.js and Picker.js as separate modules at build times so that they are properly tree-shakeable.
|
2020-06-02 06:24:46 +02:00
|
|
|
// Most of this has to happen because customElements.define() has side effects
|
2020-05-10 04:39:47 +02:00
|
|
|
const baseConfig = {
|
|
|
|
plugins: [
|
|
|
|
resolve(),
|
2020-06-02 06:24:46 +02:00
|
|
|
cjs(),
|
2020-05-17 05:36:21 +02:00
|
|
|
replace({
|
2020-06-05 03:31:31 +02:00
|
|
|
'process.env.NODE_ENV': dev ? '"development"' : '"production"',
|
2021-05-30 20:05:14 +02:00
|
|
|
'process.env.PERF': !!process.env.PERF,
|
2021-08-14 03:09:40 +02:00
|
|
|
'process.env.STYLES': JSON.stringify(buildStyles()),
|
2021-05-30 20:05:14 +02:00
|
|
|
preventAssignment: true
|
2020-05-17 05:36:21 +02:00
|
|
|
}),
|
2020-06-02 06:24:46 +02:00
|
|
|
replace({
|
2020-06-07 22:08:28 +02:00
|
|
|
'\'../database/Database.js\'': '\'./database.js\'',
|
2021-05-30 20:05:14 +02:00
|
|
|
delimiters: ['', ''],
|
|
|
|
preventAssignment: true
|
2020-06-02 06:24:46 +02:00
|
|
|
}),
|
2020-05-10 05:21:32 +02:00
|
|
|
svelte({
|
2021-06-27 18:25:54 +02:00
|
|
|
compilerOptions: {
|
|
|
|
dev
|
|
|
|
},
|
2020-06-22 03:26:11 +02:00
|
|
|
preprocess: preprocessConfig
|
2020-06-09 16:09:23 +02:00
|
|
|
}),
|
2021-07-25 18:25:39 +02:00
|
|
|
// make the svelte output slightly smaller
|
|
|
|
replace({
|
2022-05-15 00:01:18 +02:00
|
|
|
'options.anchor': 'undefined',
|
|
|
|
'options.context': 'undefined',
|
|
|
|
'options.customElement': 'undefined',
|
|
|
|
'options.hydrate': 'undefined',
|
|
|
|
'options.intro': 'undefined',
|
2021-07-25 18:25:39 +02:00
|
|
|
delimiters: ['', ''],
|
|
|
|
preventAssignment: true
|
|
|
|
}),
|
2021-05-31 17:45:59 +02:00
|
|
|
strip({
|
|
|
|
include: ['**/*.js', '**/*.svelte'],
|
|
|
|
functions: [
|
|
|
|
(!dev && !process.env.PERF) && 'performance.*',
|
|
|
|
!dev && 'console.log'
|
|
|
|
].filter(Boolean)
|
|
|
|
}),
|
2021-07-02 18:58:05 +02:00
|
|
|
DEBUG && analyze({ summaryOnly: true })
|
2020-06-02 06:24:46 +02:00
|
|
|
],
|
|
|
|
external: [
|
2020-06-07 22:08:28 +02:00
|
|
|
'./database.js',
|
2020-06-07 10:10:43 +02:00
|
|
|
'../database/Database.js'
|
2020-05-10 04:39:47 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2020-05-10 05:13:50 +02:00
|
|
|
const entryPoints = [
|
2020-05-10 04:39:47 +02:00
|
|
|
{
|
2020-06-07 10:10:43 +02:00
|
|
|
input: './src/picker/PickerElement.js',
|
2020-06-04 05:12:43 +02:00
|
|
|
output: './picker.js'
|
2020-06-02 06:24:46 +02:00
|
|
|
},
|
|
|
|
{
|
2020-06-07 05:46:03 +02:00
|
|
|
input: './src/database/Database.js',
|
2020-06-04 05:12:43 +02:00
|
|
|
output: './database.js'
|
2020-06-20 23:06:19 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
input: './src/trimEmojiData.js',
|
|
|
|
output: './trimEmojiData.js'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: './src/trimEmojiData.js',
|
|
|
|
output: './trimEmojiData.cjs',
|
|
|
|
format: 'cjs'
|
2020-06-21 20:55:27 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
input: './src/picker/PickerElement.js',
|
|
|
|
output: './svelte.js',
|
|
|
|
external: ['svelte', 'svelte/internal']
|
2020-05-10 04:39:47 +02:00
|
|
|
}
|
|
|
|
]
|
2020-05-10 05:13:50 +02:00
|
|
|
|
2020-06-21 20:55:27 +02:00
|
|
|
export default entryPoints.map(({ input, output, format = 'es', external = [] }) => {
|
|
|
|
const res = {
|
|
|
|
...baseConfig,
|
|
|
|
input,
|
|
|
|
output: {
|
|
|
|
format,
|
|
|
|
file: output,
|
2020-08-17 05:57:11 +02:00
|
|
|
sourcemap: dev,
|
|
|
|
exports: 'auto'
|
2020-06-21 20:55:27 +02:00
|
|
|
}
|
2020-05-10 05:13:50 +02:00
|
|
|
}
|
2020-06-21 20:55:27 +02:00
|
|
|
res.external = [...res.external, ...external]
|
|
|
|
return res
|
|
|
|
})
|