You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

83 lines
2.8 KiB

import { build } from "vite"
import vue from "@vitejs/plugin-vue"
import vueJsx from "@vitejs/plugin-vue-jsx"
import path from "path"
import dts from "vite-plugin-dts"
import { replaceCodePlugin } from "vite-plugin-replace";
import { getOutput, getPath, getPkgs } from "@princess-ui/share";
export default function (name: string) {
return build({
logLevel: "error",
plugins: [
replaceCodePlugin({
replacements: [
{
from: "@princess-ui/components",
to: "../",
},
// {
// from: /\@princess\-ui\/theme-chalk\/src\/(.*?)\.scss/i,
// to: "princess-ui/theme-chalk/$1.css"
// }
],
}),
vue({ isProduction: true }),
vueJsx(),
dts({
entryRoot: `components`,
tsConfigFilePath: getPath("tsconfig.json"),
outputDir: getOutput("lib"),
cleanVueFileName: true,
include: ['components/index.ts', 'components/components.ts'],
staticImport: true,
}),
],
build: {
outDir: getOutput("lib"),
emptyOutDir: false,
lib: {
entry: path.resolve(__dirname, `../components/index.ts`),
name: name,
formats: ["es", "umd"],
fileName: format => `index${format=='es'?'':'.umd'}.js`,
},
rollupOptions: {
// 确保外部化处理那些你不想打包进库的依赖
external: id => {
if (/^vue/.test(id)) {
return true
}
if (/^princess-ui/.test(id)) {
return true
}
return false
},
output: [
{
format: "es",
assetFileNames(chunkInfo) {
if (chunkInfo.name == "style.css") {
return `style.css`
}
},
globals: (id: string) => {
if (/^vue/.test(id)) {
return "Vue"
}
},
},
{
exports: "named",
format: "umd",
globals: (id: string) => {
if (/^vue/.test(id)) {
return "Vue"
}
},
},
],
},
},
})
}