-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
135 lines (126 loc) · 3.38 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
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import bundles from "./build/index";
import fs from "fs";
import path from "path";
import buble from "@rollup/plugin-buble";
import json from "@rollup/plugin-json";
import image from "@rollup/plugin-image";
function searchImages(dir, images) {
const files = fs.readdirSync(dir);
files.forEach((item, index) => {
var fullPath = path.join(dir, item);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
searchImages(path.join(dir, item), images);
} else {
if (fullPath.endsWith(".png")) {
images.push(fullPath);
}
}
});
return images;
}
const allImages = [];
searchImages("src", allImages);
function mkdirsSync(dirname) {
if (fs.existsSync(dirname)) {
return true;
} else {
if (mkdirsSync(path.dirname(dirname))) {
fs.mkdirSync(dirname);
return true;
}
}
}
allImages.forEach((value) => {
let path = __dirname + "/build/" + value;
let index = path.lastIndexOf("/");
mkdirsSync(path.substring(0, index));
fs.copyFile(
__dirname + "/" + value,
__dirname + "/build/" + value,
(error) => {
console.log(error);
}
);
});
function readDirs(dirPath, files) {
if (fs.statSync(dirPath).isDirectory()) {
fs.readdirSync(dirPath).forEach((e) => {
readDirs(path.join(dirPath, e), files);
});
} else {
for (let bundle of bundles) {
if (dirPath.match(new RegExp(`^${bundle}`))) {
files.push(dirPath);
break;
}
}
}
}
const dirs = fs.readdirSync(".").filter((e) => {
for (let bundle of bundles) {
if (bundle.match(new RegExp(`^${e}/`))) {
return true;
}
}
return false;
});
const allFiles = [];
dirs.forEach((e) => {
readDirs(e, allFiles);
});
export default allFiles
.map((e) => e.replace(/\.tsx?$/, ""))
.map((bundle) => {
return {
input: `build/${bundle}.js`,
output: {
format: "cjs",
file: `bundle/${bundle}.js`,
sourcemap: true,
},
plugins: [
resolve({ mainFields: ["jsnext"] }),
commonjs(),
json(),
image(),
],
external: ["reflect-metadata", "doric"],
onwarn: function (warning) {
if (warning.code === "THIS_IS_UNDEFINED") {
return;
}
console.warn(warning.message);
},
};
});
// If need ES5 support enable following configs
// .concat(
// allFiles
// .map((e) => e.replace(/\.tsx?$/, ""))
// .map(bundle => {
// return {
// input: `build/${bundle}.js`,
// output: {
// format: "cjs",
// file: `bundle/${bundle}.es5.js`,
// sourcemap: true,
// },
// plugins: [
// resolve({ mainFields: ["jsnext"] }),
// commonjs(),
// json(),
// buble({
// transforms: { dangerousForOf: true }
// }),
// image(),
// ],
// external: ['reflect-metadata', 'doric'],
// onwarn: function (warning) {
// if (warning.code === 'THIS_IS_UNDEFINED') { return }
// console.warn(warning.message)
// }
// }
// }))