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-cli/assets/_rollup.config.js

136 lines
3.4 KiB
JavaScript
Raw Normal View History

2021-08-31 11:59:02 +08:00
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import bundles from "./.dxx/index";
2021-08-31 11:59:02 +08:00
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) {
2021-08-31 11:59:02 +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;
}
2021-08-31 11:59:02 +08:00
const allImages = [];
searchImages("src", allImages);
function mkdirsSync(dirname) {
2021-08-31 11:59:02 +08:00
if (fs.existsSync(dirname)) {
return true;
} else {
if (mkdirsSync(path.dirname(dirname))) {
fs.mkdirSync(dirname);
return true;
}
2021-08-31 11:59:02 +08:00
}
}
allImages.forEach((value) => {
let path = __dirname + "/.dxx/" + value;
2021-08-31 11:59:02 +08:00
let index = path.lastIndexOf("/");
mkdirsSync(path.substring(0, index));
2021-08-31 11:59:02 +08:00
fs.copyFile(
__dirname + "/" + value,
__dirname + "/.dxx/" + value,
2021-08-31 11:59:02 +08:00
(error) => {
console.log(error);
}
);
});
function readDirs(dirPath, files) {
2021-08-31 11:59:02 +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.match(new RegExp(`^${bundle}`))) {
files.push(dirPath);
break;
}
}
2021-08-31 11:59:02 +08:00
}
}
2021-08-31 11:59:02 +08:00
const dirs = fs.readdirSync(".").filter((e) => {
for (let bundle of bundles) {
if (bundle.match(new RegExp(`^${e}/`))) {
return true;
}
}
return false;
});
2021-08-31 11:59:02 +08:00
const allFiles = [];
2021-08-31 11:59:02 +08:00
dirs.forEach((e) => {
readDirs(e, allFiles);
});
export default allFiles
2021-09-01 15:39:25 +08:00
.map((e) => e.replace(/\.tsx?$/, ""))
2021-08-31 11:59:02 +08:00
.map((bundle) => {
return {
input: `.dxx/${bundle}.js`,
2021-08-31 11:59:02 +08:00
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
2021-09-01 15:39:25 +08:00
// .map((e) => e.replace(/\.tsx?$/, ""))
2021-08-31 11:59:02 +08:00
// .map(bundle => {
// return {
// input: `.dxx/${bundle}.js`,
2021-08-31 11:59:02 +08:00
// 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)
// }
// }
// }))