-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.config.js
82 lines (78 loc) · 2.42 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
import _ from 'lodash';
import babel from 'rollup-plugin-babel';
import {terser} from 'rollup-plugin-terser';
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import {specs, getPluginsForSpec} from './scripts/babelTargets';
const targets = {
browser: {
format: 'umd', specs: [
{spec: specs.ES5, compress: true},
],
},
main: {
format: 'cjs', specs: [
{spec: specs.ES5},
],
},
module: {
format: 'es', specs: [
{spec: specs.ES5, ext: 'es'},
{spec: specs.ES2015, ext: specs.ES2015},
{spec: specs.ES2018, ext: specs.ES2018},
{spec: specs.ES2019, ext: specs.ES2019},
],
},
};
export default function ({packageName, umdName, input, getExtraConfig = () => {}, getExtraPresets, getExtraPlugins}) {
return Object.entries(targets).reduce((config, [target, {format, specs}]) =>
config.concat(specs.reduce((config, {spec, ext = format, compress = false}) => {
config.push(_.merge(
{
input: `${input}`,
output: {
format,
name: umdName,
sourcemap: compress,
file: `dist/${packageName}.${ext}.js`,
},
plugins: _.compact([
resolve({
extensions: ['.ts', '.tsx'],
customResolveOptions: {
moduleDirectory: 'node_modules',
},
}),
typescript({
check: true,
clean: true,
verbosity: 1,
abortOnError: true,
tsconfig: './tsconfig.compiler.json',
tsconfigOverride: {
compilerOptions: {
composite: false,
declaration: false,
declarationMap: false,
baseUrl: '.',
paths: {
'@css-modules-theme/core': ['packages/core/src'],
'@css-modules-theme/core/types': ['packages/core/src/types'],
},
},
},
}),
babel({
exclude: 'node_modules/**',
extensions: ['.ts', '.tsx'],
...getPluginsForSpec(spec, getExtraPresets, getExtraPlugins),
}),
compress && terser({sourcemap: compress}),
]),
},
getExtraConfig({target, format, specs, spec, ext})
));
return config;
}, [])),
[]);
}