-
Notifications
You must be signed in to change notification settings - Fork 151
/
rollup.config.js
95 lines (93 loc) · 2.3 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
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
90
91
92
93
94
95
import path from 'path'
import globImport from 'rollup-plugin-glob-import'
import alias from '@rollup/plugin-alias'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import serve from 'rollup-plugin-serve'
import copy from 'rollup-plugin-copy'
import typescript from '@rollup/plugin-typescript'
import dts from 'rollup-plugin-dts'
function commonPlugins() {
return [
alias({
entries: [
{
find: 'mobiledoc-kit',
replacement: path.join(__dirname, 'src/js'),
},
],
}),
resolve({ extensions: ['.js', '.ts'] }),
commonjs(),
typescript({ noEmitOnError: false }),
]
}
export default args => [
{
input: 'src/js/index.ts',
plugins: [
...commonPlugins(),
copy({
targets: [
{ src: 'src/css/mobiledoc-kit.css', dest: ['dist', 'dist/website/demo'], rename: 'mobiledoc.css' },
{ src: 'demo', dest: 'dist/website' },
{ src: 'dist/mobiledoc.*', dest: 'dist/website/demo' },
],
hook: 'writeBundle',
}),
...(args.watch
? [
{
name: 'watch-external',
buildStart() {
const demoFiles = ['demo.js', 'demo.css', 'index.html']
demoFiles.forEach(f => this.addWatchFile(path.join(__dirname, 'demo', f)))
},
},
serve({
contentBase: 'dist/website',
port: process.env.PORT || 4200, // eslint-disable-line no-process-env
}),
]
: []),
],
output: {
file: 'dist/mobiledoc.js',
format: 'es',
sourcemap: true,
},
},
{
input: 'src/js/index.ts',
plugins: commonPlugins(),
output: {
file: 'dist/mobiledoc.cjs',
format: 'cjs',
sourcemap: true,
},
},
{
input: 'src/js/index.ts',
plugins: [dts()],
output: {
file: 'dist/mobiledoc.d.ts',
format: 'es',
},
},
{
input: 'tests/index.ts',
plugins: [
...commonPlugins(),
globImport({
// without this option, the plugin will try to parse imported files (as
// JS) and fail with TS files
format: 'import',
}),
],
output: {
file: 'dist/tests.js',
format: 'es',
sourcemap: true,
},
},
]