-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrollup.config.js
103 lines (91 loc) · 2.91 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
97
98
99
100
101
102
103
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: "" }
};
}
};
}
const providerPackageName = "@igloo-ui/provider";
export function createRollupConfig(packageName) {
const { component, style } = handleName(packageName);
const external = ["react"];
if (packageName !== providerPackageName) {
// @igloo-ui/provider uses a context that needs to be shared with other packages that uses it
// as a peer dependency. So any package referencing @igloo-ui/provider should mark it as external,
// except the provider itself.
external.push(providerPackageName);
}
return {
input: path.resolve(__dirname, `./src/${component}.tsx`),
output: {
file: path.resolve(DIST, `${component}.js`),
format: FORMAT,
name: component,
sourcemap: true
},
external,
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"]
})
]
};
}