93 lines
1.9 KiB
JavaScript
93 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,
|
|
emptyOutDir: false
|
|
},
|
|
plugins: [
|
|
dts({
|
|
copyDtsFiles: true
|
|
})
|
|
]
|
|
});
|
|
}
|