forked from torch2424/responsive-gamepad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
104 lines (97 loc) · 2.18 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
103
104
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import serve from 'rollup-plugin-serve';
import bundleSize from 'rollup-plugin-bundle-size';
import postcss from 'rollup-plugin-postcss';
import postcssImport from 'postcss-import';
import compiler from '@ampproject/rollup-plugin-closure-compiler';
import json from 'rollup-plugin-json';
import pkg from './package.json';
const fs = require('fs');
const writeIndexHtmlToBuild = bundleName => {
let indexHtml = fs.readFileSync('demo/index.html', 'utf8');
indexHtml = indexHtml.replace('<%BUNDLE%>', bundleName.replace('build/', ''));
if (!fs.existsSync('build/')){
fs.mkdirSync('build/');
}
fs.writeFileSync('build/index.html', indexHtml, 'utf8');
};
const babelPluginConfig = {
exclude: ['node_modules/**'],
plugins: [
['@babel/plugin-proposal-class-properties'],
['@babel/plugin-proposal-object-rest-spread'],
['@babel/plugin-transform-react-jsx', { pragma: 'h' }],
['@babel/plugin-proposal-export-default-from']
]
};
let plugins = [
json({
exclude: 'node_modules/**'
}),
postcss({
extensions: ['.css'],
plugins: [postcssImport()]
}),
babel(babelPluginConfig),
resolve(),
commonjs()
];
if (process.env.ROLLUP_WATCH) {
plugins = [
...plugins,
serve({
contentBase: ['dist/', 'build/', 'lib/'],
port: 8080
})
]
}
writeIndexHtmlToBuild('index.iife.js');
export default [
{
input: 'lib/index.js',
output: [
{
file: pkg.main,
format: 'cjs'
},
{
file: pkg.module,
format: 'es'
},
{
file: pkg.iife,
format: 'iife',
name: 'ResponsiveGamepad'
},
{
file: pkg.browser,
format: 'umd',
name: 'ResponsiveGamepad'
}
],
plugins : [
...plugins,
compiler(),
bundleSize()
]
},
{
input: 'lib/index.js',
output: [
{
file: pkg.main,
format: 'cjs'
}
],
plugins
},
{
input: 'demo/index.js',
output: [
{ file: 'build/index.iife.js', format: 'iife' }
],
plugins
}
];