generated from sonofmagic/npm-lib-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
55 lines (51 loc) · 1.36 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
import typescript from '@rollup/plugin-typescript'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import pkg from './package.json'
import replace from '@rollup/plugin-replace'
import { terser } from 'rollup-plugin-terser'
// const isProd = process.env.NODE_ENV === 'production'
const isDev = process.env.NODE_ENV === 'development'
const isAction = process.env.BUILD_TARGET === 'action'
/** @type {import('rollup').OutputOptions} */
const npmOutput = {
file: pkg.main,
format: 'cjs',
sourcemap: isDev,
exports: 'auto'
}
/** @type {import('rollup').OutputOptions} */
const actionOutput = {
dir: 'lib',
format: 'cjs',
exports: 'auto'
}
/** @type {import('rollup').RollupOptions} */
const config = {
input: 'src/index.ts',
output: isAction ? actionOutput : npmOutput,
plugins: [
isAction ? terser() : undefined,
replace({
preventAssignment: true,
values: {
__isAction__: JSON.stringify(isAction)
}
}),
json(),
nodeResolve({
preferBuiltins: true
}),
commonjs(),
typescript({
tsconfig: isAction ? './tsconfig.action.json' : './tsconfig.build.json',
sourceMap: isDev
})
],
external: [
...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),
'fs/promises'
]
}
export default config