-
Notifications
You must be signed in to change notification settings - Fork 12
/
rollup.config.js
96 lines (85 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
import babel from 'rollup-plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import external from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import resolve from '@rollup/plugin-node-resolve';
import url from '@rollup/plugin-url';
import svgr from '@svgr/rollup';
import pkg from './package.json';
const glob = require('glob');
/*
* Generate an instance for each "config"
*/
function getPlugins() {
return [
external(),
postcss({
extract: true,
modules: true,
use: ['sass']
}),
url(),
svgr(),
babel({
exclude: 'node_modules/**',
plugins: []
}),
resolve(),
commonjs()
];
}
/*
* Base Config
*/
const baseConfig = {
input: 'src/index.js',
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true
},
{
file: pkg.module,
format: 'es',
sourcemap: true
}
],
plugins: getPlugins()
};
const allConfigs = [];
allConfigs.push(baseConfig);
/*
* Build a rollup config for every component
*
* https://github.com/egoist/rollup-plugin-postcss/issues/160
*
* Generate a CSS output for each component so we can selectively pull in per-component styles
*
* The downside to this approach is the JS code is output twice. Once because we're exporting it
* for easy import, and once for the css file generation.
*
* rollup-plugin-postcss is only good at consolidating css output, and does not seem actively maintained
* We would need to fork it, and allow for per css input file output
*/
const modularStyles = false; // Leaving here for future evaluation, but not currently in use
if (modularStyles) {
const componentEntryPoints = glob.sync('./src/components/*/index.js');
componentEntryPoints.forEach(entryPoint => {
const outputs = baseConfig.output;
const plugins = getPlugins();
const outputPath = entryPoint
.replace('src/', 'dist/')
.replace('/index.js', '');
const config = {
...baseConfig,
input: entryPoint,
output: outputs.map(outputDest => {
return { ...outputDest, file: outputPath };
}),
plugins
};
allConfigs.push(config);
});
}
export default allConfigs;