-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
95 lines (82 loc) · 2.13 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 commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import strip from '@rollup/plugin-strip';
import replace from '@rollup/plugin-replace';
import html from '@rollup/plugin-html';
import { terser } from 'rollup-plugin-terser';
import fs from 'fs';
import path from 'path';
import pkg from './package.json';
/**
* Extensions for node_modules resolution
*/
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
/**
* Name for browser JS file
*/
const name = 'ImageSketchpad';
/**
* Rollup config
*/
const config = {
input: './src/index.ts',
plugins: [
// Allows node_modules resolution
resolve({ extensions }),
// Allow bundling cjs modules. Rollup doesn't understand cjs
commonjs(),
// Compile TypeScript/JavaScript files
babel({
extensions,
babelHelpers: 'runtime',
include: ['src/**/*'],
}),
strip(),
// Replace strings in files
replace({
'%%date%%': () => new Date().toString(),
'%%version%%': pkg.version,
preventAssignment: true,
}),
],
output: [
// Output one common js package
{ file: pkg.main, format: 'cjs', exports: 'default' },
// Output one es module package
{ file: pkg.module, format: 'es' },
// Output one browser package
{
file: pkg.browser,
format: 'umd',
name,
},
// Output one browser minified package
{
file: pkg.browser.replace('.js', '.min.js'),
format: 'umd',
name,
plugins: [
terser({
mangle: {
reserved: ['ImageSketchpad'],
},
}),
html({
fileName: 'index.html',
template: ({ files }) => {
let html = fs.readFileSync(path.resolve('example', 'index.html')).toString();
for (let jsFile of files.js) {
if (!jsFile.isEntry) {
continue;
}
html = html.replace('</body>', `<script src="${jsFile.fileName}"></script></body>`);
}
return html;
},
}),
],
},
],
};
export default config;