Files
ui-lib/vite.build.js
T
lchen a0fe4cb7b1 1.0.12:
exports: [
  ".",
  "./global",
  "./style.css",
  "./types",
  "./utility"
]
2026-11-18 13:44:06 +08:00

94 lines
1.9 KiB
JavaScript

import { build } from "vite";
import { rmSync } from 'node:fs';
import { resolve } from 'node:path';
import dts from 'unplugin-dts/vite';
import postcssPresetEnv from "postcss-preset-env";
// empty out dir
rmSync(resolve('dist'), { recursive: true, force: true });
const libraries = [
{
name: 'utility',
path: resolve('./lib/utility.js')
},
{
name: 'ui',
path: resolve('./lib/ui.js')
},
/*/
{
name: 'app',
path: resolve('./lib/app.js'),
rolldownOptions: {
external: ['../../ui'],
output: {
format: 'umd',
globals(id) {
let index = id.lastIndexOf('/');
if (index < 0) {
index = id.lastIndexOf('\\');
}
id = id.substring(index + 1);
switch (id) {
case 'ui': return 'lib-ui';
default: return id;
}
}
}
}
},
{
name: 'element',
path: resolve('./lib/element.js'),
rolldownOptions: {
external: ['../ui'],
output: {
format: 'umd',
globals(id) {
let index = id.lastIndexOf('/');
if (index < 0) {
index = id.lastIndexOf('\\');
}
id = id.substring(index + 1);
switch (id) {
case 'ui': return 'lib-ui';
default: return id;
}
}
}
}
},//*/
]
for (const { name, path, rolldownOptions } of libraries) {
await build({
clearScreen: false,
css: {
postcss: {
plugins: [postcssPresetEnv()]
}
},
build: {
lib: {
entry: {
[name]: path
},
name: `lib-${name}`,
cssFileName: `${name}.min`,
formats: ['umd'],
fileName: (_format, name) => `${name}.js`
},
rolldownOptions,
sourcemap: true,
minify: false,
emptyOutDir: false
},
plugins: [
dts({
copyDtsFiles: true
})
]
});
}