-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
136 lines (128 loc) · 3.94 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import fs from "fs";
import path from "path";
import { defineConfig } from "rollup";
import { dts } from "rollup-plugin-dts";
import RollupCopy from "rollup-plugin-copy";
import RollupBabel from "@rollup/plugin-babel";
import RollupTerser from "@rollup/plugin-terser";
import RollupCommonJs from "@rollup/plugin-commonjs";
import RollupResolve from "@rollup/plugin-node-resolve";
import RollupTypescript from "@rollup/plugin-typescript";
import pkg from "./package.json" assert { type: "json" };
/**
* Configuração para realizar o build
*/
const __dir = "./src";
const __folder = fs.readdirSync(__dir).filter(file => fs.statSync(path.join(__dir, file)).isDirectory());
const __dependeciesExternal = [
"react",
"axios",
"jquery",
"react-dom",
"bootstrap",
"sweetalert2",
"node-snackbar",
"primereact/utils",
"primereact/editor",
"primereact/column",
"primereact/datatable",
"primereact/autocomplete",
"@webdatarocks/react-webdatarocks",
"@tiptap/starter-kit",
"@tiptap/react",
"@tiptap/pm",
"@tiptap/extension-underline",
"@tiptap/extension-text-style",
"@tiptap/extension-link",
"@tiptap/extension-image",
"@tiptap/extension-highlight",
"@tiptap/extension-color",
];
/**
* Gera o package.json do pacote a ser publicado
*/
function addPackageJson() {
const outputDir = path.join("./dist");
const packageJson = `{
"name": "${pkg.name}",
"version": "${pkg.version}",
"private": false,
"author": "${pkg.author}",
"description": "${pkg.description}",
"repository": {
"type": "git",
"url": "https://github.com/Nandovga/orangesix-react.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/Nandovga/orangesix-react/issues"
},
"keywords": ${JSON.stringify(pkg.keywords, null, 2)},
"dependencies": ${JSON.stringify(pkg.dependencies, null, 2)}
}`;
fs.writeFileSync(path.join(outputDir, "package.json"), packageJson);
}
/**
* Realiza a leitura da pasta "src" para gerar o build dos components
*/
const components = __folder.map(folder => {
return {
input: `./src/${folder}/index`,
output: [
{
file: `./dist/${folder}/index.cjs.js`,
format: "cjs",
sourcemap: true
},
{
file: `./dist/${folder}/index.esm.js`,
format: "esm",
sourcemap: true
},
],
external: __dependeciesExternal,
plugins: [
RollupBabel({
exclude: "node_modules/**",
babelHelpers: "bundled",
presets: [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
]
}),
RollupCopy({
targets: [
{ src: `./src/${folder}/package.json`, dest: `./dist/${folder}/` },
{ src: `./src/${folder}/css/theme.css`, dest: `./dist/${folder}/` },
{ src: `./src/${folder}/_${folder}.scss`, dest: `./dist/${folder}/` },
],
verbose: true
}),
RollupTerser(),
RollupCommonJs(),
RollupTypescript({
tsconfig: "./tsconfig.json",
noEmitOnError: true
}),
RollupResolve({
extensions: [".js", ".jsx", ".ts", ".tsx"]
}),
]
};
});
/**
* Realiza a leitura da pasta "src" para gerar o index.d.ts dos components
*/
const componentsDts = __folder.map(folder => {
return {
input: `./src/${folder}/index.ts`,
output: {
file: `./dist/${folder}/index.d.ts`,
format: "es"
},
plugins: [dts()]
};
});
addPackageJson();
export default defineConfig([...components, ...componentsDts]);