-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
rollup.config.mjs
61 lines (57 loc) · 1.69 KB
/
rollup.config.mjs
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
import { createRequire } from 'node:module'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodeResolve from '@rollup/plugin-node-resolve'
import esbuild from 'rollup-plugin-esbuild'
import { prebundleAlias, prebundleConfig } from './rollup.prebundle.config.mjs'
const require = createRequire(import.meta.url)
const pkg = require('./package.json')
const { compilerOptions } = require('./tsconfig.json')
const external = (id) =>
Object.keys(pkg.dependencies).some(
(dep) => dep === id || id.startsWith(`${dep}/`),
)
const plugins = [
prebundleAlias,
json({ preferConst: true }),
esbuild({
minify: !process.env.ROLLUP_WATCH,
target: compilerOptions.target,
}),
nodeResolve(),
commonjs(),
]
export default [
prebundleConfig,
{
external,
plugins,
input: 'src/index.ts',
output: { dir: 'lib', exports: 'named', format: 'cjs', compact: true },
},
{
external,
plugins,
input: ['src/jsx-runtime.ts', 'src/jsx-dev-runtime.ts'],
output: { dir: 'lib', exports: 'named', format: 'cjs', compact: true },
},
{
external,
plugins,
input: ['src/index.ts', 'src/jsx-runtime.ts', 'src/jsx-dev-runtime.ts'],
output: {
chunkFileNames: '[name]-[hash].mjs',
dir: 'module',
entryFileNames: '[name].mjs',
exports: 'named',
format: 'es',
compact: true,
preserveModules: true, // to emit tree-shakable scripts
// https://github.com/rollup/rollup/issues/3684#issuecomment-1535836196
entryFileNames: (chunkInfo) =>
chunkInfo.name.includes('node_modules')
? `${chunkInfo.name.replace('node_modules', 'vendor')}.mjs`
: '[name].mjs',
},
},
]