This repository was archived by the owner on Jan 28, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathrollup.config.js
More file actions
202 lines (187 loc) · 4.62 KB
/
Copy pathrollup.config.js
File metadata and controls
202 lines (187 loc) · 4.62 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import nodeResolve from 'rollup-plugin-node-resolve';
import globals from 'rollup-plugin-node-globals';
import builtins from 'rollup-plugin-node-builtins';
import commonjs from 'rollup-plugin-commonjs';
import replace from 'rollup-plugin-replace';
import json from 'rollup-plugin-json';
import babel from 'rollup-plugin-babel';
import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
// import visualizer from 'rollup-plugin-visualizer';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import url from 'rollup-plugin-url';
import copy from 'rollup-plugin-copy';
import glob from 'glob';
import nodemon from 'nodemon';
import pkg from './package.json';
const { devenv } = pkg;
const productionMode = process.env.NODE_ENV === 'production';
// commonjs: require
// ES: ES6 Imports
// UMD: IIFE
const config = [];
const serveConfig = {
// Launch in browser (default: false)
open: true,
// Folder to serve files from
contentBase: 'public',
// Set to true to return index.html (200) instead of error page (404)
historyApiFallback: true,
// Path to fallback page
// historyApiFallback: '/200.html',
// Options used in setting up server
host: 'localhost',
port: devenv.port || 3000,
// By default server will be served over HTTP (https: false). It can optionally be served over HTTPS
// https: {
// key: fs.readFileSync('/path/to/server.key'),
// cert: fs.readFileSync('/path/to/server.crt'),
// ca: fs.readFileSync('/path/to/ca.pem'),
// },
//set headers
// headers: {
// 'Access-Control-Allow-Origin': '*',
// foo: 'bar',
// },
};
const pluginsList = [
copy({
targets: [...glob.sync('public/**/*')],
}),
postcss(),
json(),
url({
limit: 10 * 1024, // inline files < 10k, copy files > 10k
}),
globals(),
builtins(),
nodeResolve({
extensions: ['.mjs', '.js', '.jsx', '.json'],
}),
// commonjs({
// include: ['node_modules/**', 'src/**'],
// }),
babel({
// exclude: 'node_modules/**',
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
boolFunc(
productionMode,
terser({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
},
}),
),
boolFunc(devenv.server && !devenv.node, serve(serveConfig)),
boolFunc(devenv.server && !devenv.node, livereload()),
// boolFunc(productionMode, visualizer()),
];
// CommonJs / Require
if (!devenv.application && productionMode) {
config.push({
input: 'src/app.js',
output: {
file: `lib/${devenv.name}.js`,
format: 'cjs',
indent: false,
},
external: Object.keys(pkg.dependencies || {}),
plugins: pluginsList,
});
}
// ES / ES6 Imports
if (!devenv.application && productionMode) {
config.push({
input: 'src/app.js',
output: {
file: `es/${devenv.name}.js`,
format: 'es',
indent: false,
},
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
plugins: pluginsList,
});
}
// ES / ES6 Imports for Browser
if (!devenv.application && productionMode) {
config.push({
input: 'src/app.js',
output: {
file: `es/${devenv.name}.mjs`,
format: 'es',
indent: false,
},
plugins: pluginsList,
});
}
// UMD / IIFE for Development
if (!productionMode) {
config.push({
input: 'src/app.js',
output: {
file: `dev/app.js`,
format: 'umd',
name: devenv.name,
indent: false,
sourcemap: 'inline',
},
external: devenv.node
? [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
]
: [],
plugins: pluginsList,
});
}
// UMD / IIFE for Production
if (productionMode) {
config.push({
input: 'src/app.js',
output: {
file: devenv.application
? `prod/app.js`
: `dist/${devenv.name}.min.js`,
format: 'umd',
name: devenv.name,
indent: false,
},
external: [
...boolFunc(
devenv.node,
[
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
[],
),
],
plugins: pluginsList,
});
}
if (devenv.server && devenv.node) {
nodemon({
script: 'dev/app.js',
});
// exec: boolFunc(devenv.debug, 'node --inspect', undefined),
nodemon.on('restart', files => console.clear());
}
export default config;
function boolFunc(ifElm, thenElm, elseElm) {
if (ifElm && thenElm) {
return thenElm;
} else if (elseElm) {
return elseElm;
}
return null;
}