mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-08-27 00:39:55 +08:00
* feat: 升级 vite5 * fix: 优化 webpack publicPath * fix: 优化文档 * chore: remove log * chore: remove 无效代码
72 lines
2.4 KiB
JavaScript
72 lines
2.4 KiB
JavaScript
import { join } from 'node:path';
|
|
import { existsSync } from 'node:fs';
|
|
import vue from '@vitejs/plugin-vue';
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
import { createHtmlPlugin } from './vite-plugin-html';
|
|
import SFCConfigBlockPlugin from './SFCConfigBlockPlugin';
|
|
import getDefine from './getDefine';
|
|
|
|
function getPostcssConfig(api) {
|
|
// TODO 支持其他 postcss 配置文件类型
|
|
const configPath = `${api.paths.cwd}/postcss.config.js`;
|
|
if (existsSync(configPath))
|
|
return require(`${api.paths.cwd}/postcss.config.js`);
|
|
|
|
return {};
|
|
}
|
|
|
|
export function getInnerCommonConfig(api) {
|
|
const { deepmerge, resolveRuntimeEnv } = api.utils;
|
|
const { base, ...otherViteOption } = api.config.viteOption;
|
|
|
|
const publicPath = base || api.config.publicPath || '/';
|
|
|
|
return deepmerge(
|
|
{
|
|
base: publicPath,
|
|
configFile: false,
|
|
define: getDefine(api, publicPath),
|
|
cacheDir: join(api.cwd, '.cache'),
|
|
css: {
|
|
postcss: {
|
|
...getPostcssConfig(api),
|
|
},
|
|
},
|
|
plugins: [
|
|
vue(api.config.viteVuePlugin || {}),
|
|
SFCConfigBlockPlugin,
|
|
vueJsx(api.config.viteVueJsx || {}),
|
|
createHtmlPlugin(
|
|
deepmerge(
|
|
{
|
|
minify: true,
|
|
// 使用绝对地址在win下会提示没有权限
|
|
entry: `/src/${api.paths.tmpDir}/fes.js`,
|
|
template: 'index.html',
|
|
inject: {
|
|
data: {
|
|
...resolveRuntimeEnv(publicPath),
|
|
title: api.config.title || 'Fes.js',
|
|
mountElementId: api.config.mountElementId,
|
|
},
|
|
},
|
|
},
|
|
api.config.viteHtml,
|
|
),
|
|
),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
...api.config.alias,
|
|
'@': api.paths.absSrcPath,
|
|
'@@': api.paths.absTmpPath,
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
exclude: ['@fesjs/fes'],
|
|
},
|
|
},
|
|
otherViteOption,
|
|
);
|
|
}
|