-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
rollup.config.mjs
89 lines (84 loc) · 1.75 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
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
// @ts-check
import * as fs from 'node:fs'
import ts from 'rollup-plugin-esbuild'
import dts from 'rollup-plugin-dts'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
/** @type {import('./package.json')} */
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
const entries = {
index: 'src/index.ts',
webpack: 'src/webpack.ts',
vite: 'src/vite.ts',
rollup: 'src/rollup.ts',
esbuild: 'src/esbuild.ts',
nuxt: 'src/nuxt.ts',
types: 'src/types.ts',
}
const external = [
...Object.keys(pkg.dependencies),
...Object.keys(pkg.peerDependencies),
'esbuild',
'rollup',
'vite',
'webpack',
'@nuxt/kit',
]
/** @type {import('rollup').RollupOptions[]} */
export default [
{
input: entries,
external,
plugins: [
alias({
entries: [
{ find: /^node:(.+)$/, replacement: '$1' },
],
}),
resolve({
preferBuiltins: true,
}),
json(),
commonjs(),
ts(),
],
onwarn({ code, message }) {
if(code === 'EMPTY_BUNDLE') return
console.error(message)
},
output:[
{
dir: 'dist',
format: 'esm',
sourcemap: 'inline',
entryFileNames: "[name].mjs",
},
{
dir: 'dist',
format: 'cjs',
exports: 'named',
sourcemap: 'inline',
entryFileNames: "[name].js",
},
]
},
{
input: entries,
external,
plugins: [
dts({ respectExternal: true }),
],
output: [
{
dir: 'dist',
entryFileNames: "[name].d.mts",
},
{
dir: 'dist',
entryFileNames: "[name].d.ts",
},
],
},
]