/
rollup.config.js
88 lines (85 loc) · 2.48 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
import typescriptPlugin from "rollup-plugin-typescript2";
import sass from "node-sass";
import postcss from "rollup-plugin-postcss";
import autoprefixer from "autoprefixer";
import presetEnv from "postcss-preset-env";
import flexbugFixes from "postcss-flexbugs-fixes";
import { DEFAULT_EXTENSIONS } from "@babel/core";
import babel from "rollup-plugin-babel";
import replace from "rollup-plugin-replace";
import commonjs from "rollup-plugin-commonjs";
// import docGenPlugin from "babel-plugin-react-docgen-typescript";
import ttypescript from "ttypescript";
import execute from "rollup-plugin-execute";
import pkg from "./package.json";
const NODE_ENV = process.env.NODE_ENV || "development";
const __DEV__ = NODE_ENV === "development";
const dependencies = Object.keys(pkg.dependencies || {});
const isStoryBuild = NODE_ENV === "storybook";
export default {
input: "src/index.ts",
output: [
{
file: pkg.main,
format: "cjs",
sourcemap: true
},
{
file: "dist/index.esm.js",
format: "esm",
sourcemap: true
}
],
external: dependencies,
plugins: [
replace({
__DEV__,
exclude: "node_modules/**"
}),
typescriptPlugin({
typescript: ttypescript,
tsconfig: "./tsconfig.build.json"
}),
babel({
babelrc: false,
extensions: [...DEFAULT_EXTENSIONS, ".ts", ".tsx"],
exclude: "node_modules/**",
presets: ["@babel/preset-react"]
// plugins: [
// isStoryBuild && [
// docGenPlugin,
// {
// docgenCollectionName: "STORYBOOK_REACT_CLASSES",
// // TODO: Look into this -> May be able to speed up the build if we limit the included files
// include: "components.*\\.tsx$",
// exclude: "stories\\.tsx$"
// }
// ]
// ].filter(Boolean)
}),
postcss({
preprocessor: (content, id) => {
return new Promise((resolve, reject) => {
const result = sass.renderSync({ file: id });
resolve({ code: result.css.toString() });
});
},
plugins: [
autoprefixer,
flexbugFixes,
presetEnv({
autoprefixer: {
flexbox: "no-2009"
},
stage: 3
})
],
sourceMap: true,
// Automatically inject styles into document head at runtime. (Does not output a css bundle)
extract: false,
autoModules: true
}),
commonjs(),
execute("cp ./dist/index.d.ts ./dist/index.esm.d.ts")
]
};