This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-demo/rollup.config.js

141 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-09-01 10:47:40 +08:00
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";
2020-04-18 15:59:21 +08:00
function searchImages(dir, images) {
2021-09-01 10:47:40 +08:00
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;
2020-04-18 15:59:21 +08:00
}
2021-09-01 10:47:40 +08:00
const allImages = [];
searchImages("src", allImages);
2020-04-18 15:59:21 +08:00
function mkdirsSync(dirname) {
2021-09-01 10:47:40 +08:00
if (fs.existsSync(dirname)) {
return true;
} else {
if (mkdirsSync(path.dirname(dirname))) {
fs.mkdirSync(dirname);
return true;
2020-04-18 15:59:21 +08:00
}
2021-09-01 10:47:40 +08:00
}
2020-04-18 15:59:21 +08:00
}
allImages.forEach((value) => {
2021-09-01 10:47:40 +08:00
let path = __dirname + "/build/" + value;
path = path.split("\\").join("/");
let index = path.lastIndexOf("/");
mkdirsSync(path.substring(0, index));
2020-04-18 15:59:21 +08:00
2021-09-01 10:47:40 +08:00
fs.copyFile(
__dirname + "/" + value,
__dirname + "/build/" + value,
(error) => {
if (error) console.log(error);
}
);
});
2019-12-04 14:07:14 +08:00
2019-12-18 15:28:32 +08:00
function readDirs(dirPath, files) {
2021-09-01 10:47:40 +08:00
if (fs.statSync(dirPath).isDirectory()) {
fs.readdirSync(dirPath).forEach((e) => {
readDirs(path.join(dirPath, e), files);
});
} else {
for (let bundle of bundles) {
if (dirPath.replace("\\", "/").match(new RegExp(`^${bundle}`))) {
files.push(dirPath);
}
2019-12-04 14:07:14 +08:00
}
2021-09-01 10:47:40 +08:00
}
2019-12-18 15:28:32 +08:00
}
2021-09-01 10:47:40 +08:00
const dirs = fs.readdirSync(".").filter((e) => {
for (let bundle of bundles) {
if (bundle.match(new RegExp(`^${e}/`))) {
return true;
}
}
return false;
});
2019-12-18 15:28:32 +08:00
2021-09-01 10:47:40 +08:00
const allFiles = [];
2019-12-18 15:28:32 +08:00
2021-09-01 10:47:40 +08:00
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);
},
};
})
.concat(
2020-01-15 17:24:11 +08:00
allFiles
2021-09-01 10:47:40 +08:00
.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,
generator: false,
},
}),
image(),
],
external: ["reflect-metadata", "doric"],
onwarn: function (warning) {
if (warning.code === "THIS_IS_UNDEFINED") {
return;
2020-01-15 17:24:11 +08:00
}
2021-09-01 10:47:40 +08:00
console.warn(warning.message);
},
};
})
);