-
Notifications
You must be signed in to change notification settings - Fork 24
/
rollup.config.js
95 lines (90 loc) · 2.94 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
// rollup.config.js
import svelte from 'rollup-plugin-svelte'
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import sveltePreprocess from 'svelte-preprocess'
import themePlugin from './src/postcss/theme.js'
import path from 'path'
import genTypes from './src/scripts/gen-types.js'
import genWebBindings from './src/scripts/gen-web-bindings.js'
import genReactBindings from './src/scripts/gen-react-bindings.js'
import { getSvelteFiles } from './src/scripts/common.js'
import { onwarn } from './svelte.config.js'
// Entry points are all our Svelte components + the react bindings for those
// components.
const COMPONENTS_FOLDER = path.resolve('./', 'src', 'components')
const inputs = []
for await (const file of getSvelteFiles(COMPONENTS_FOLDER, false)) {
inputs.push(file)
}
inputs.push('./src/components/svelte-react.ts')
inputs.push('./src/components/svelte-web.ts')
inputs.push('./src/components/applyTheme.ts')
inputs.push('./src/components/dialogHelpers.ts')
export default {
input: inputs,
// Note we output in ESM & AMD formats to make it easier to consume Leo from
// different places.
output: {
sourcemap: true,
dir: './',
chunkFileNames: 'shared/[hash].js',
entryFileNames: ({ name }) => `shared/${name}.js`,
format: 'esm'
},
// React is external - Leo doesn't need it but its React bindings do. We'll
// use whatever version of React the consumer is using, but we don't want it
// to be a peer dependency.
external: ['react'],
plugins: [
typescript({
declaration: true,
declarationDir: './types',
sourceMap: true
}),
// Emit type declarations for non-component helpers to the shared folder.
typescript({
declaration: true,
emitDeclarationOnly: true,
declarationDir: './shared',
include: ['src/components/**/*.ts']
}),
svelte({
include: 'src/components/**/*.svelte',
preprocess: sveltePreprocess({
postcss: {
plugins: [
themePlugin({
wrapSelector: (selector) => `:global(:host-context(${selector}))`
})
]
}
}),
// Don't emit CSS - it doesn't work properly with Web Components.
emitCss: false,
compilerOptions: {
customElement: false
},
onwarn
}),
resolve({ browser: true }),
{
name: 'postBuildCopySvelteTypesAndGenerateBindings',
buildEnd: {
async handler() {
// To get the type definitions working properly for consumers we create
// a copy of the type definitions in the types folder.
await genTypes({
baseDir: './',
outputDir: './types'
})
// Generate Web Components
await genWebBindings('./src/components')
// Once we have the type definitions, we can generate the React
// wrapper.
await genReactBindings('./src/components')
}
}
}
]
}