-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.js
102 lines (99 loc) · 2.97 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
96
97
98
99
100
101
102
import { version } from './package.json';
import alias from '@rollup/plugin-alias';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonJs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import typescript from 'rollup-plugin-typescript2';
import { terser } from 'rollup-plugin-terser';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import bundleSize from 'rollup-plugin-bundle-size';
const build = process.env.BUILD || 'development';
const devserver = process.env.DEV_SERVER || false;
const isEsmoduleBuild = process.env.ES_MODULE || false;
const isProdBuild = build === 'production';
const banner = `/*!!
pd-usb v${ version }
JavaScript library for interacting with a Panic Playdate console over USB
https://github.com/cranksters/pd-usb
2022 James Daniel
Playdate is (c) Panic Inc. - this project isn't affiliated with or endorsed by them in any way
*/`;
module.exports = {
input: [
'src/index.ts'
],
output: [
(isEsmoduleBuild) && {
file: 'dist/pd-usb.es.js',
format: 'es',
name: 'pdusb',
exports: 'named',
banner: banner,
sourcemap: devserver ? true : false,
sourcemapFile: 'dist/pd-usb.es.map'
},
(!isEsmoduleBuild) && {
file: isProdBuild ? 'dist/pd-usb.min.js' : 'dist/pd-usb.js',
format: 'umd',
name: 'pdusb',
exports: 'named',
banner: banner,
sourcemap: devserver ? true : false,
sourcemapFile: isProdBuild ? 'dist/pd-usb.min.js.map' : 'dist/pd-usb.js.map'
},
].filter(Boolean),
plugins: [
nodeResolve({
// browser: true
}),
commonJs(),
alias({
resolve: ['.jsx', '.js', '.ts', '.tsx'],
}),
replace({
preventAssignment: true,
LIBRARY_VERSION: JSON.stringify(version),
PROD: isProdBuild ? 'true' : 'false',
DEV_SERVER: devserver ? 'true' : 'false',
// https://github.com/PolymerLabs/lit-element-starter-ts/blob/master/rollup.config.js
'Reflect.decorate': 'undefined'
}),
typescript({
abortOnError: false,
typescript: require('typescript'),
tsconfigOverride: {
compilerOptions: {
target: (() => {
if (isEsmoduleBuild)
return 'es2020';
else
return 'es6';
})(),
declaration: !devserver ? true : false,
sourceMap: devserver ? true : false,
},
},
}),
bundleSize(),
// devserver + livereload
devserver && serve({
contentBase: ['dist', 'examples']
}),
devserver && livereload({
watch: 'dist'
}),
// only minify if we're producing a non-es production build
isProdBuild && !isEsmoduleBuild && terser({
// preserve banner comment
output: {
comments: function(node, comment) {
if (comment.type === 'comment2') {
return /\!\!/i.test(comment.value);
}
return false;
}
}
})
].filter(Boolean)
};