-
Notifications
You must be signed in to change notification settings - Fork 26
/
rollup.config.js
85 lines (80 loc) · 2.12 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
import copy from 'rollup-plugin-copy';
import typescript from '@rollup/plugin-typescript';
import { terser } from 'rollup-plugin-terser';
import getBabelOutputPlugin from '@rollup/plugin-babel';
import CleanCSS from 'clean-css';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version, author, license } = require('./package.json');
const banner = `Pushin.js - v${version}\nAuthor: ${author}\nLicense: ${license}`;
function createConfig(format) {
return {
input: 'src/index.ts',
output: {
format,
sourcemap: true,
file: `dist/${format}/pushin.js`,
name: format === 'umd' ? 'pushin' : undefined,
banner: `/* ${banner} */`,
},
plugins: [
copy({
targets: [{ src: 'src/pushin.css', dest: 'dist' }],
}),
typescript({
tsconfig: './tsconfig.json',
compilerOptions:
format === 'esm'
? {
sourceMap: true,
declaration: true,
declarationDir: '.',
}
: {},
}),
],
};
}
/** This outputs a minified JS file which can then be shipped to CDN. */
function createConfigForCdn() {
return {
input: 'src/index.ts',
output: {
format: 'umd',
sourcemap: false,
file: 'dist/umd/pushin.min.js',
name: 'pushin',
banner: `/* ${banner} */`,
},
plugins: [
copy({
targets: [
{
src: 'src/pushin.css',
dest: 'dist',
transform: contents => new CleanCSS().minify(contents).styles,
rename: 'pushin.min.css',
},
],
}),
typescript({ tsconfig: './tsconfig.json' }),
terser({
ecma: '5',
mangle: true,
compress: true,
}),
getBabelOutputPlugin({
babelHelpers: 'bundled',
presets: [
[
'@babel/preset-env',
{
targets:
'> 0.25%, last 2 versions, Firefox ESR, not dead, IE 9-11',
},
],
],
}),
],
};
}
export default [createConfig('umd'), createConfig('esm'), createConfigForCdn()];