代码拉取完成,页面将自动刷新
同步操作将从 easysoft/zui 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import Path, {dirname} from 'path';
import fs from 'fs-extra';
import {defineConfig, mergeConfig, type UserConfig, type LibraryOptions} from 'vite';
import {blue} from 'colorette';
import eslint from 'vite-plugin-eslint';
import {viteZip} from 'vite-plugin-zip-file';
import preact from '@preact/preset-vite';
import configDevServer from './scripts/dev/config-server';
import {getLibs} from './scripts/libs/query';
import {LibInfo} from './scripts/libs/lib-info';
function getLibByPath(path: string, libsCache: Record<string, LibInfo>): LibInfo | undefined {
const nodeModulesFlag = `${Path.sep}node_modules${Path.sep}`;
const nodeModulesIndex = path.indexOf(nodeModulesFlag);
if (nodeModulesIndex > -1) {
const nodeModulePath = path.substring(nodeModulesIndex + nodeModulesFlag.length);
return Object.values(libsCache).find((x) => nodeModulePath.startsWith(`${x.name}${Path.sep}`));
}
return Object.values(libsCache).find((x) => path.startsWith(`${x.zui.path}${Path.sep}`));
}
export default defineConfig(async ({mode}) => {
const buildLibs = process.env.BUILD_LIBS ?? 'buildIn';
const libsCache: Record<string, LibInfo> | undefined = await getLibs(buildLibs.split(','));
const configFile = process.env.VITE_EXTRA_CONFIG;
let extraBuildConfig: Partial<UserConfig> | undefined;
let libFileName = 'zui';
if (configFile) {
const configFromFile = Path.isAbsolute(configFile) ? configFile : Path.resolve(__dirname, configFile);
extraBuildConfig = await fs.readJSON(configFromFile);
const lib = extraBuildConfig?.build?.lib;
if (lib && typeof lib.fileName === 'string') {
libFileName = lib.fileName || libFileName;
}
console.log(blue('merged extra vite config file:'), '\n', Path.relative(__dirname, configFromFile) + '\n');
}
let viteConfig: UserConfig = {
base: './',
build: {
outDir: 'dist/dev',
rollupOptions: {
output: {
assetFileNames: (chunkInfo) => {
if (chunkInfo.name == 'style.css' && viteConfig.build?.lib) {
return `${libFileName}.css`;
}
return chunkInfo.name ?? 'noname';
},
},
},
assetsInlineLimit: 256,
sourcemap: true,
cssMinify: false,
},
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
jsxInject: 'import {h} from \'preact\'',
},
resolve: {
preserveSymlinks: true,
alias: [
{find: /^@zui\/(.*)/, replacement: `${__dirname}/lib/$1`},
{find: 'zui-dev', replacement: `${__dirname}/dev`},
{find: 'zui-config', replacement: `${__dirname}/config`},
{find: '~/', replacement: `${__dirname}/`},
{find: '@/', replacement: '/', customResolver: (source, importer) => {
if (!importer) {
return;
}
const lib = getLibByPath(importer, libsCache);
if (!lib) {
return Path.join(__dirname, source);
}
if (source.startsWith('/public/') && mode !== 'development') {
return `/${lib.zui.publicPath || lib.zui.name}/${source.replace('/public/', '')}`;
}
return Path.join(lib.zui.path, source);
}},
...Object.values(libsCache).reduce<{find: string, replacement: string}[]>((aliasList, info) => {
if (info.zui.sourceType === 'exts') {
aliasList.push({find: info.name, replacement: info.zui.path});
if (info.zui.replace) {
aliasList.push({find: info.zui.replace, replacement: info.zui.path});
}
}
return aliasList;
}, []),
],
},
define: {
'process.env.NODE_ENV': JSON.stringify(mode),
},
experimental: {
renderBuiltUrl(filename: string, {type}: {hostId: string, hostType: 'js' | 'css' | 'html', type: 'public' | 'asset'}) {
if (type === 'public') {
return `./${filename}`;
}
return {relative: true};
},
},
};
if (extraBuildConfig) {
viteConfig = mergeConfig(viteConfig, extraBuildConfig);
const lib = viteConfig.build!.lib as LibraryOptions;
lib.fileName = (format) => {
if (format === 'umd') {
return `${libFileName}.js`;
}
if (format === 'es') {
return `${libFileName}.esm.js`;
}
return `${libFileName}.${format}.js`;
};
}
viteConfig = mergeConfig(viteConfig, {
plugins: [
eslint(),
...(mode === 'development' ? [
preact(),
configDevServer({
rootPath: __dirname,
}),
] : []),
...(process.env.ZIP ? [
viteZip({
folderPath: viteConfig.build!.outDir,
outPath: process.env.ZIP_OUT ?? dirname(viteConfig.build!.outDir!),
zipName: process.env.ZIP,
}),
] : []),
],
});
return viteConfig;
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。