forked from carbon-design-system/ibm-security
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
75 lines (67 loc) · 1.72 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
/**
* @file Rollup configuration.
* @copyright IBM Security 2019
*/
import autoprefixer from 'autoprefixer';
import { resolve } from 'path';
import { union } from 'ramda';
import babel from 'rollup-plugin-babel';
import postcss from 'rollup-plugin-postcss';
import nodeResolve from 'rollup-plugin-node-resolve';
import { paths } from './config';
import { dependencies, peerDependencies } from './package.json';
process.env.BABEL_ENV = 'rollup';
const { src, dist } = paths;
const { cjs, es } = dist;
const createFromDefault = ({
experimentalCodeSplitting = true,
externals = union(Object.keys(dependencies), Object.keys(peerDependencies)),
format = 'cjs',
input = {
'scss-exports': resolve(src.path, 'globals/scss-exports/index.js'),
},
out = cjs,
} = {}) => ({
experimentalCodeSplitting,
input,
output: {
chunkFileNames: 'chunks/[hash].js',
[experimentalCodeSplitting ? 'dir' : 'file']: resolve(__dirname, out),
format,
},
// Mark all dependencies and peer dependencies as external, except imported JSON files.
external: id =>
externals.some(
extensionId =>
(id === extensionId || id.startsWith(`${extensionId}/`)) &&
!id.endsWith('.json')
),
plugins: [
postcss({
extract: false,
inject: false,
minimize: !(process.env.NODE_ENV === 'development'),
namedExports: name => name.replace(/-/, '_'),
plugins: [autoprefixer],
use: [
[
'sass',
{
includePaths: ['node_modules'],
},
],
],
}),
babel({ runtimeHelpers: true }),
nodeResolve(),
],
});
export default [
createFromDefault({
out: cjs,
}),
createFromDefault({
format: 'es',
out: es,
}),
];