generated from Liinkiing/node-rollup-typescript-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup.config.js
58 lines (54 loc) · 1.44 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
import pkg from './package.json'
import replace from '@rollup/plugin-replace'
import resolve from '@rollup/plugin-node-resolve'
import ts from '@wessberg/rollup-plugin-ts'
import { eslint } from 'rollup-plugin-eslint'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import json from '@rollup/plugin-json'
import sourcemaps from 'rollup-plugin-sourcemaps'
import { builtinModules } from 'module'
const env = JSON.stringify(
process.env.NODE_ENV ||
(process.env.ROLLUP_WATCH ? 'development' : 'production')
)
const watch = process.env.ROLLUP_WATCH
/** @type {import('rollup').RollupOptions} */
const config = {
input: ['src/index.ts'],
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
{
file: pkg.module,
format: 'esm',
sourcemap: true,
},
],
external: [
...builtinModules,
...(pkg.dependencies == null ? [] : Object.keys(pkg.dependencies)),
...(pkg.devDependencies == null ? [] : Object.keys(pkg.devDependencies)),
...(pkg.peerDependencies == null ? [] : Object.keys(pkg.peerDependencies)),
],
plugins: [
replace({
preventAssignment: true,
'process.env.NODE_ENV': env,
}),
resolve({ preferBuiltins: true }),
eslint({
include: ['src/**'],
configFile: './.eslintrc',
}),
ts(),
json(),
commonjs(),
!watch && terser(),
watch && sourcemaps(),
],
}
export default config