emoji-picker-element/rollup.config.js

114 lines
2.9 KiB
JavaScript
Raw Normal View History

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'
import strip from '@rollup/plugin-strip'
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
const { NODE_ENV, DEBUG } = process.env
const dev = NODE_ENV !== 'production'
2020-05-31 18:34:17 +02:00
const preprocessConfig = preprocess()
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
res.code = res.code.replace(/([>}])\s+([<{])/sg, '$1$2')
2020-06-25 17:44:54 +02:00
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
2020-05-10 04:39:47 +02:00
const baseConfig = {
plugins: [
resolve(),
cjs(),
2020-05-17 05:36:21 +02:00
replace({
'process.env.NODE_ENV': dev ? '"development"' : '"production"',
2021-05-30 20:05:14 +02:00
'process.env.PERF': !!process.env.PERF,
'process.env.STYLES': JSON.stringify(buildStyles()),
2021-05-30 20:05:14 +02:00
preventAssignment: true
2020-05-17 05:36:21 +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-05-10 05:21:32 +02:00
svelte({
compilerOptions: {
dev
},
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({
'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
}),
strip({
include: ['**/*.js', '**/*.svelte'],
functions: [
(!dev && !process.env.PERF) && 'performance.*',
!dev && 'console.log'
].filter(Boolean)
}),
DEBUG && analyze({ summaryOnly: true })
],
external: [
2020-06-07 22:08:28 +02:00
'./database.js',
'../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
{
input: './src/picker/PickerElement.js',
2020-06-04 05:12:43 +02:00
output: './picker.js'
},
{
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,
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
})