-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
55 lines (53 loc) · 1.6 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
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import babel from "@rollup/plugin-babel";
import json from "@rollup/plugin-json";
import { terser } from "rollup-plugin-terser";
import copy from "rollup-plugin-copy";
import postcss from "rollup-plugin-postcss";
import postcssUrl from "postcss-url";
const components = [
{ name: "advent-announce", input: "src/advent-announce/advent-announce.jsx" },
{ name: "footer-menu", input: "src/footer-menu/footer-menu.jsx" },
{ name: "header-menu", input: "src/header-menu/header-menu.jsx" },
];
export default components.map((component) => ({
input: component.input,
output: {
file: `dist/${component.name}/index.js`,
format: "cjs",
},
plugins: [
resolve(),
commonjs(),
babel({
babelHelpers: "bundled",
exclude: "node_modules/**",
presets: ["@babel/preset-env", "@babel/preset-react"],
}),
json(),
postcss({
plugins: [
postcssUrl({
url: (asset) => {
if (asset.url.startsWith("../../images")) {
return asset.url.replace("../../images", "./images");
} else if (asset.url.startsWith("../../../images")) {
return asset.url.replace("../../../images", "./images");
}
return asset.url;
},
}),
],
extract: true,
minimize: true,
}),
copy({
targets: [
{ src: `src/${component.name.toLowerCase()}/images/*`, dest: `dist/${component.name}/images` },
],
}),
terser(),
],
external: ["react", "react-dom", "next"],
}));