-
Notifications
You must be signed in to change notification settings - Fork 10
/
rollup.config.js
84 lines (75 loc) · 1.95 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
import * as path from "path"
import * as fs from "fs"
import peerDepsExternal from "rollup-plugin-peer-deps-external"
import resolve from "@rollup/plugin-node-resolve"
import commonjs from "@rollup/plugin-commonjs"
import typescript from "rollup-plugin-typescript2"
import postcss from "rollup-plugin-postcss"
import json from "@rollup/plugin-json"
import babel from "@rollup/plugin-babel"
import sass from "sass"
/**entries */
const entry = "components/index.ts"
const componentsDir = "components/packages"
const componentsName = fs.readdirSync(path.resolve(componentsDir))
const componentsEntry = componentsName.map(
(name) => `${componentsDir}/${name}/index.ts`
)
const isProd = process.env.NODE_ENV === "production"
const BABEL_ENV = process.env.BABEL_ENV
const babelOptions = {
presets: ["@babel/preset-env"],
extensions: [".js", ".jsx", ".ts", ".tsx", ".scss"],
exclude: "**/node_modules/**",
}
const commonPlugins = [
peerDepsExternal(),
resolve(),
commonjs({ sourceMap: !isProd }),
typescript(),
babel(babelOptions),
json(),
]
const externalConfig = [
(id) => /\/__expample__|main.tsx/.test(id),
"react",
"react-dom",
"classname",
"react-is",
"@fortawesome/fontawesome-svg-core",
"@fortawesome/free-solid-svg-icons",
"@fortawesome/react-fontawesome",
"**/node_modules/**",
]
const processScss = function (context) {
return new Promise((resolve, reject) => {
sass.compile({ file: context }, (err, result) => {
err ? reject(result) : resolve(reject)
})
})
}
const esmOutput = {
preserveModules: true,
}
function esmConfig() {
return {
input: [entry, ...componentsEntry],
output: { ...esmOutput, dir: "dist/", format: "es" },
external: externalConfig,
plugins: [
postcss({
extract: true,
process: processScss,
}),
...commonPlugins,
],
}
}
export default () => {
switch (BABEL_ENV) {
case "esm":
return esmConfig()
default:
return esmConfig()
}
}