This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
rollup.config.js
80 lines (68 loc) · 1.81 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
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import sass from 'rollup-plugin-sass';
import postcss from 'postcss';
import prefixer from 'postcss-class-prefix';
import cssnano from 'cssnano';
import pkg from './package.json';
const extend = (a, b) => ({ ...a, ...b });
const classPrefix = '📖-';
const baseConfig = {
input: 'build/index.js',
};
const baseOutput = {
name: 'Bindery',
intro: `
const BINDERY_VERSION = 'v${pkg.version}';
const BINDERY_CLASS_PREFIX = '${classPrefix}';
`,
banner: `/* 📖 Bindery v${pkg.version} */`,
};
const sassPlugin = ({ shouldMinify } = {}) => sass({
insert: true,
processor: (css) =>
postcss(
shouldMinify
? [prefixer(classPrefix), cssnano()]
: [prefixer(classPrefix)],
)
.process(css)
.then(result => result.css),
});
// browser-friendly UMD build
const umd = extend(baseConfig, {
output: extend(baseOutput, {
file: pkg.browser,
format: 'umd',
sourcemap: true,
}),
plugins: [resolve(), commonjs(), sassPlugin()],
});
// minified browser-friendly build
const mini = extend(baseConfig, {
output: extend(baseOutput, {
file: 'dist/bindery.min.js',
format: 'iife',
sourcemap: true,
}),
plugins: [
resolve(),
commonjs(),
sassPlugin({ shouldMinify: true }),
terser({
ecma: 2018,
}),
],
});
// CommonJS (for Node) and ES module (for bundlers) build.
const modules = extend(baseConfig, {
output: [
extend(baseOutput, { file: pkg.main, format: 'cjs' }),
extend(baseOutput, { file: pkg.module, format: 'es' }),
],
external: ['regionize'],
plugins: [resolve(), sassPlugin()],
});
const outputs = process.env.BUILD === 'prod' ? [umd, mini, modules] : umd;
export default outputs;