forked from dockwa/simple-react-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
97 lines (89 loc) · 2.85 KB
/
rollup.config.mjs
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
import copy from "rollup-plugin-copy";
import { babel } from "@rollup/plugin-babel";
import replace from "@rollup/plugin-replace";
import { minify } from "rollup-plugin-esbuild";
import serve from "rollup-plugin-serve";
import { glob } from "glob";
import path from "node:path";
import { camelCase, upperFirst } from "lodash-es";
import pack from "./package.json" assert { type: "json" };
const isDev = process.env.BUILD === "development";
const defaultBuildOptions = {
entryFileNames: "[name].js",
globals: {
react: "react",
},
banner: `/** Simple React Validator v${pack.version} | Created By Dockwa | Edited by EgoMaw | MIT License | 2017 - Present */`,
};
function capitalizeFilename(file) {
return upperFirst(camelCase(path.basename(file, ".js")));
}
const localeConfigs = glob.sync("src/locale/*.js").map((file) => {
return {
input: file,
external: [/simple-react-validator/],
output: [
{
dir: "dist/umd/locale",
name: `SimpleReactValidatorLocale${capitalizeFilename(file)}`,
globals: function (id) {
return id.endsWith("simple-react-validator") ? "SimpleReactValidator" : id;
},
format: "umd",
},
{
dir: "dist/esm/locale",
format: "es",
},
],
plugins: [
babel({
exclude: "node_modules/**",
babelHelpers: "bundled",
}),
minify({
banner: `/** Simple React Validator v${pack.version} | Created By Dockwa | Edited by EgoMaw | MIT License | 2017 - Present */`
}),
],
};
});
/**
* @type {import('rollup').RollupOptions}
*/
export default [
{
input: "src/simple-react-validator.js",
external: ["react", /@babel\/runtime/],
output: [
{
dir: "dist/umd",
name: "SimpleReactValidator",
format: "umd",
...defaultBuildOptions,
},
{
dir: "dist/esm",
format: "es",
...defaultBuildOptions,
},
],
plugins: [
replace({
__VERSION__: pack.version,
preventAssignment: true,
}),
copy({
targets: [{ src: "src/index.d.ts", dest: "dist" }],
}),
babel({
exclude: "node_modules/**",
babelHelpers: "bundled",
}),
minify({
banner: `/** Simple React Validator v${pack.version} | Created By Dockwa | Edited by EgoMaw | MIT License | 2017 - Present */`
}),
isDev && serve({ contentBase: ['docs', 'dist'], verbose: true }),
],
},
...localeConfigs,
];