-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
executable file
·111 lines (99 loc) · 2.65 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
104
105
106
107
108
109
110
111
const babel = require("rollup-plugin-babel");
const postcssModule = require("postcss");
const cssnanoMachines = require("cssnano");
const postcss = require('rollup-plugin-postcss');
const wpResolve = require("@rollup/plugin-node-resolve");
const autoprefixer = require("autoprefixer");
const nodeResolve = require("@rollup/plugin-node-resolve");
const scss = require("rollup-plugin-scss");
const json = require("@rollup/plugin-json");
const resolve = require("@rollup/plugin-node-resolve").default;
const commonjs = require("@rollup/plugin-commonjs");
const typescript = require("@rollup/plugin-typescript");
const visualizer = require("rollup-plugin-visualizer").visualizer;
const { terser } = require("rollup-plugin-terser");
const fs = require("fs");
const getFiles = (entry, extensions = [], excludeExtensions = []) => {
let fileNames = [];
const dirs = fs.readdirSync(entry);
dirs.forEach((dir) => {
const path = `${entry}/${dir}`;
if (fs.lstatSync(path).isDirectory()) {
fileNames = [
...fileNames,
...getFiles(path, extensions, excludeExtensions),
];
return;
}
if (
!excludeExtensions.some((exclude) => dir.endsWith(exclude)) &&
extensions.some((ext) => dir.endsWith(ext))
) {
fileNames.push(path);
}
});
return fileNames;
};
export default {
input: [...getFiles("./src", [".ts", ".tsx", ".json", ".scss"])],
output: {
dir: "dist",
format: "es",
exports: "named",
sourcemap: true,
},
plugins: [
scss({
output: "dist/style-index.css",
sourceMap: true,
processor: () =>
postcssModule([
autoprefixer(),
cssnanoMachines({
preset: "default",
}),
]),
include: ["src/style.scss"],
}),
scss({
output: "dist/index.css",
sourceMap: true,
processor: () =>
postcssModule([
autoprefixer(),
cssnanoMachines({
preset: "default",
}),
]),
include: ["src/editor.scss"],
}),
resolve(),
commonjs(),
json(),
typescript({
tsconfig: "./tsconfig.build.json",
declaration: true,
sourceMap: true,
declarationDir: "dist",
}),
terser(),
visualizer({
filename: "bundle-analysis.html",
open: true,
}),
nodeResolve({
extensions: [".js", ".jsx", ".ts", ".tsx"],
}),
babel({
presets: ["@babel/preset-react", "@babel/preset-typescript", "@babel/preset-env"],
extensions: [".js", ".jsx", ".ts", ".tsx"],
}),
wpResolve(),
postcss({
modules: true,
cssnano: {
preset: "default",
},
})
],
};