forked from kettanaito/create-typescript-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.ts
55 lines (50 loc) · 1.23 KB
/
rollup.config.ts
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 * as path from 'path'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import typescript from 'rollup-plugin-typescript2'
import packageJson from './package.json'
const plugins = [
json(),
resolve({
mainFields: ['module', 'main', 'jsnext:main', 'browser'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
}),
typescript({
// Emit declarations in the specified directory
// instead of next to each individual built target.
useTsconfigDeclarationDir: true,
}),
commonjs(),
]
const buildEsm = {
input: ['src/index.ts'],
output: {
format: 'esm',
entryFileNames: '[name].js',
chunkFileNames: '[name]-deps.js',
dir: path.dirname(packageJson.module),
},
plugins,
}
const buildUmd = {
input: 'src/index.ts',
output: {
format: 'umd',
esModule: false,
file: packageJson.main,
name: packageJson.name.replace(/(?:^|-)(\w)/g, (_, letter) =>
letter.toUpperCase()
),
},
plugins,
}
const buildCjs = {
input: 'src/index.ts',
output: {
format: 'cjs',
file: path.resolve(path.dirname(packageJson.types), 'cjs/index.js'),
},
plugins,
}
export default [buildEsm, buildUmd, buildCjs]