-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.ts
122 lines (116 loc) · 3.28 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import nodeResolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import glslify from 'rollup-plugin-glslify';
import minifyHtml from 'rollup-plugin-html-literals';
// @ts-ignore
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import {
cleanDir,
banner,
replacements,
svg,
minify,
size,
} from './buildSupport';
const isServer = (!!process.env.SERVER) || false;
const doBuild = (input: string, outputBase: string, opts: {
name?: string,
} = {}) => ({
input,
plugins: [
// Resolve node module imports
nodeResolve(),
// .ts compilation
typescript({
outputToFilesystem: true,
exclude: [
'buildSupport/**/*',
'rollup.config.ts'
],
compilerOptions: {
rootDir: 'src',
// Generate .d.ts files from TypeScript declarations
declaration: true,
declarationDir: `dist/types/`,
},
sourceMap: opts.name !== undefined,
inlineSources: isServer,
}),
// Replace version number and other strings
replacements(),
// Process GLSL shaders for WebGL
glslify(),
// Process HTML for web components
!isServer && minifyHtml(),
// Process SVG for web components
svg(),
// Dev server w/ hot reload
isServer && serve({
contentBase: ['dist', 'test']
}),
isServer && livereload({
watch: ['dist']
}),
].filter(Boolean),
output: [
// ES module build
!isServer && {
banner,
file: `dist/esm/${outputBase}.mjs`,
format: 'es',
exports: 'named',
},
// Legacy CommonJS module build
!isServer && {
banner,
file: `dist/cjs/${outputBase}.cjs`,
format: 'cjs',
exports: 'named',
},
// Browser build - the only one used in server mode
opts.name && {
banner,
name: opts.name,
file: `dist/${ outputBase }.js`,
format: 'iife',
exports: 'named',
sourcemap: true,
sourcemapFile: `dist/${ outputBase }.js.map`,
plugins: [size()]
},
// Minified browser build
opts.name && !isServer && {
banner,
name: opts.name,
file: `dist/${ outputBase }.min.js`,
format: 'iife',
exports: 'named',
sourcemap: true,
sourcemapFile: `dist/${ outputBase }.min.js.map`,
plugins: [minify(), size()]
},
// Demo site browser build
opts.name && !isServer && {
name: opts.name,
file: `www/public/${outputBase}.min.js`,
format: 'iife',
exports: 'named',
sourcemap: true,
sourcemapFile: `www/public/${outputBase}.min.js.map`,
plugins: [minify()]
}
].filter(Boolean),
});
cleanDir('./dist');
export default [
// Main bundles - one with the webcomponent player included, one without
doBuild('./src/flipnote.webcomponent.ts', 'flipnote.webcomponent', { name: 'flipnote' }),
!isServer && doBuild('./src/flipnote.ts', 'flipnote', { name: 'flipnote' }),
// Partial bundles
!isServer && doBuild('./src/parsers/PpmParser.ts', 'PpmParser'),
!isServer && doBuild('./src/parsers/KwzParser.ts', 'KwzParser'),
!isServer && doBuild('./src/Player/index.ts', 'Player'),
!isServer && doBuild('./src/renderers/index.ts', 'renderers'),
!isServer && doBuild('./src/utils/index.ts', 'utils'),
].filter(Boolean);