forked from gsoft-inc/ov-igloo-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
93 lines (83 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
import path from 'path';
import typescript from 'rollup-plugin-typescript2';
import cleanup from 'rollup-plugin-cleanup';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import postcss from 'rollup-plugin-postcss';
import camelcase from 'camelcase';
import alias from '@rollup/plugin-alias';
import autoprefixer from 'autoprefixer';
import flexbugs from 'postcss-flexbugs-fixes';
const SCOPE = '@igloo-ui';
const DIST = './dist';
const FORMAT = 'es';
function capitalize(string) {
return camelcase(string, { pascalCase: true });
}
function handleName(name) {
if (!name) return null;
const componentName = name.replace(`${SCOPE}/`, '');
const component = capitalize(componentName);
const style = componentName;
return {
component,
style,
};
}
function injectCssImport(file) {
return {
name: 'plugin-css-import',
renderChunk(code) {
return {
code: `import './${file}';\n${code}`,
map: { mappings: '' },
};
},
};
}
export function createRollupConfig(packageName) {
const { component, style } = handleName(packageName);
return {
input: path.resolve(__dirname, `./src/${component}.tsx`),
output: {
file: path.resolve(DIST, `${component}.js`),
format: FORMAT,
name: component,
sourcemap: true,
},
external: ['react'],
plugins: [
postcss({
plugins: [autoprefixer(), flexbugs()],
extract: path.resolve(DIST, `${style}.css`),
minimize: true,
}),
alias({
entries: {
find: '@shared/components',
replacement: '../../../shared/components',
},
}),
resolve(),
json(),
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
exclude: ['**/*.stories.*', '**/*.test.*'],
},
clean: true,
tsconfig: path.resolve(__dirname, './tsconfig.json'),
}),
commonjs({
exclude: 'node_modules',
ignoreGlobal: true,
}),
injectCssImport(`${style}.css`),
cleanup({
comments: 'none',
extensions: ['.ts'],
}),
],
};
}