forked from nichollascarter/subjx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
127 lines (116 loc) · 2.87 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import postcss from 'rollup-plugin-postcss';
import { terser } from 'rollup-plugin-terser';
import { uglify } from 'rollup-plugin-uglify';
import { eslint } from 'rollup-plugin-eslint';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
// eslint-disable-next-line no-undef
const { NODE_ENV = 'production', LIVE_MODE = 'disable' } = process.env;
const liveMode = LIVE_MODE === 'enable';
const prod = NODE_ENV === 'production';
const libraryName = 'subjx';
const banner = `/*@license
* Drag/Rotate/Resize Library
* Released under the MIT license, 2018-2021
* Karen Sarksyan
*/`;
const input = './src/js/index.js';
let libraryFileName = libraryName;
if (!prod) {
libraryFileName += '.dev';
}
const plugins = [
postcss({
minimize: true,
extract: 'dist/style/subjx.css'
}),
eslint({
exclude: 'node_modules/**',
throwOnError: prod
}),
resolve()
];
const uglifyPlugin = () => (
uglify({
compress:
{
evaluate: false
},
output: {
preamble: banner
}
})
);
const uglifyESMPlugin = () => terser();
const babelPlugins = [
babel({
exclude: 'node_modules/**',
presets: ['@babel/preset-env']
})
];
const umdPlugins = [
...babelPlugins,
prod && uglifyPlugin()
];
export default [
...(prod ? [{
input,
output: [{
file: `dist/js/${libraryName}.esm.js`,
format: 'esm',
banner
}],
plugins: [
...plugins,
...babelPlugins
]
}] : []),
{
input,
output: [{
file: `dist/js/${libraryFileName}.common.js`,
format: 'cjs',
banner
}],
plugins: [
...plugins,
...babelPlugins,
prod && uglifyESMPlugin()
]
},
{
input,
output: [{
name: libraryName,
file: `dist/js/${libraryFileName}.js`,
format: 'umd',
banner
}],
plugins: [
...plugins,
...umdPlugins
]
},
...(
liveMode
? [{
input,
output: [{
name: libraryName,
file: `public/${libraryFileName}.js`,
format: 'umd',
banner
}],
plugins: [
...plugins,
serve(['public', 'dist']),
livereload('dist'),
...umdPlugins
]
}]
: []
)
];