2022-04-23 19:22:32 +08:00
|
|
|
import { UserConfigExport } from "vite";
|
|
|
|
import vue from "@vitejs/plugin-vue";
|
|
|
|
import { resolve } from "path";
|
|
|
|
import * as fs from "fs";
|
|
|
|
|
|
|
|
const inputDir = resolve(process.cwd(), "./src/component");
|
|
|
|
|
|
|
|
const inputsArray = fs.readdirSync(inputDir).filter((name) => {
|
|
|
|
const componentDir = resolve(inputDir, name);
|
|
|
|
const isDir = fs.lstatSync(componentDir).isDirectory();
|
|
|
|
return isDir && fs.readdirSync(componentDir).includes("index.ts");
|
|
|
|
});
|
|
|
|
|
|
|
|
const inputs = inputsArray.reduce((backObj, pkgName) => {
|
|
|
|
backObj[pkgName] = resolve(
|
|
|
|
process.cwd(),
|
|
|
|
`./src/component/${pkgName}/index.ts`
|
|
|
|
);
|
|
|
|
return backObj;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
inputs["index"] = resolve(process.cwd(), "./src/index.ts");
|
|
|
|
const matchModule: string[] = [
|
2022-04-23 23:44:18 +08:00
|
|
|
"input",
|
|
|
|
"dropdown",
|
|
|
|
"carousel",
|
|
|
|
"transition",
|
|
|
|
"datePicker",
|
|
|
|
"header",
|
|
|
|
"selectOption",
|
|
|
|
"skeletonItem",
|
|
|
|
"tabItem",
|
|
|
|
"upload",
|
2022-04-23 19:22:32 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
export default (): UserConfigExport => {
|
|
|
|
return {
|
|
|
|
publicDir: false,
|
|
|
|
resolve: {
|
|
|
|
alias: [
|
|
|
|
{
|
|
|
|
find: "@",
|
|
|
|
replacement: resolve(process.cwd(), "./"),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
css: {
|
|
|
|
preprocessorOptions: {
|
|
|
|
less: {
|
|
|
|
javascriptEnabled: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
postcss: {},
|
|
|
|
},
|
|
|
|
plugins: [vue()],
|
|
|
|
build: {
|
|
|
|
cssCodeSplit: true,
|
|
|
|
emptyOutDir: true,
|
2022-04-23 23:44:18 +08:00
|
|
|
outDir: "es",
|
2022-04-23 19:22:32 +08:00
|
|
|
lib: {
|
|
|
|
entry: resolve(process.cwd(), "./src/index.ts"),
|
|
|
|
formats: ["es"],
|
|
|
|
},
|
|
|
|
rollupOptions: {
|
|
|
|
input: inputs,
|
|
|
|
output: {
|
|
|
|
globals: {
|
|
|
|
vue: "Vue",
|
|
|
|
},
|
2022-04-23 23:44:18 +08:00
|
|
|
manualChunks(id) {
|
|
|
|
let arr = id.toString().split("/");
|
|
|
|
if (id.includes("node_modules")) {
|
2022-04-23 19:54:50 +08:00
|
|
|
//id => layui-vue/node_modules/.pnpm/@vue+devtools-api@6.1.4/node_modules/@vue/devtools-api/lib/esm/api/app.js
|
|
|
|
const chunksName = "_chunks/";
|
2022-04-23 23:44:18 +08:00
|
|
|
return (
|
|
|
|
chunksName +
|
|
|
|
id.toString().split("node_modules/")[2].split("/")[0].toString()
|
|
|
|
);
|
|
|
|
} else if (arr.length >= 2) {
|
2022-04-23 19:54:50 +08:00
|
|
|
//if (arr.length >= 2 && arr[arr.length - 1].split('.')[1] != 'ts'){
|
2022-04-23 23:44:18 +08:00
|
|
|
let entryPoint = arr[arr.length - 2].toString();
|
2022-04-23 19:22:32 +08:00
|
|
|
if (matchModule.includes(entryPoint)) {
|
|
|
|
return entryPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
chunkFileNames: ({ name }) => {
|
2022-04-23 23:44:18 +08:00
|
|
|
console.log(name);
|
2022-04-23 19:22:32 +08:00
|
|
|
return name === "index" ? "index.js" : "[name]/index.js";
|
|
|
|
},
|
|
|
|
entryFileNames: ({ name }) => {
|
|
|
|
return name === "index" ? "index.js" : "[name]/index.js";
|
|
|
|
},
|
|
|
|
assetFileNames: "[name]/index.css",
|
2022-04-23 23:44:18 +08:00
|
|
|
},
|
2022-04-23 19:22:32 +08:00
|
|
|
external: ["vue", "vue-router"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|