1.杂谈
先说点没用的,本段可以不看。
到目前为止,我们配置安装了27个开发依赖了。而此时我手上的VbenAdmin
有63个开发依赖,运行依赖还没开始。。。我们安装的依赖一般都没有到。根目录下的必要的配置文件也还有大致2-3个没有分析(文件夹不算)。package.json
中的脚本也还有5个未完成。(以上的数据没有仔细数。)
大神牛逼也正是牛逼在这,有时架构一个系统时,各个依赖之间的关系复杂,很难理出一个头绪,只能凭经验见招拆招。亦或者从一个点出发要绕很多弯才会回来形成一个闭环。
本章也说了只是准备。因为接下来的阶段如果是我自己研究源码,可以随意处理。但是如果要理出一个头绪,我觉得从这个Vite
配置准备开始吧。
如果我表达大家不太喜欢,也请诸位理解,因为此时的VbenAdmin
和众多前端技术在我面前是晦涩难懂的。
2.说明
现在我们准备攻克vite.config.ts
这个文件。
本章只是准备,大家可以直接把VbenAdmin
的vite.config.ts
原代码复制到我们的项目中。然后把报错的地方注释掉。接下来的章节会把这个文件一段一段的解析出来。章节做太长了大家应该也不喜欢看,至少我不喜欢看长文章。
3.我的代码
import type { UserConfig, ConfigEnv } from 'vite';
import { loadEnv } from 'vite';
import { resolve } from 'path';
// import { generateModifyVars } from './build/config/themeConfig';
// import { createProxy } from './build/vite/proxy';
// import { wrapperEnv } from './build/utils';
// import { createVitePlugins } from './build/vite/plugin';
// import { OUTPUT_DIR } from './build/constant';
function pathResolve(dir: string) {
return resolve(__dirname, '.', dir);
}
export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd();
const env = loadEnv(mode, root);
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
// const viteEnv = wrapperEnv(env);
// const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_LEGACY } = viteEnv;
// const isBuild = command === 'build';
return {
// base: VITE_PUBLIC_PATH,
root,
resolve: {
alias: [
{
// /@/xxxx => src/xxx
find: /^\/@\//,
replacement: pathResolve('src') + '/',
},
{
// /#/xxxx => types/xxx
find: /^\/#\//,
replacement: pathResolve('types') + '/',
},
],
},
server: {
// port: VITE_PORT,
// Load proxy configuration from .env
// proxy: createProxy(VITE_PROXY),
hmr: {
overlay: true,
},
},
build: {
// minify: 'esbuild',
// outDir: OUTPUT_DIR,
// polyfillDynamicImport: VITE_LEGACY,
terserOptions: {
compress: {
keep_infinity: true,
// Used to delete console in production environment
// drop_console: VITE_DROP_CONSOLE,
},
},
// Turning off brotliSize display can slightly reduce packaging time
brotliSize: false,
chunkSizeWarningLimit: 1200,
},
define: {
// setting vue-i18-next
// Suppress warning
__VUE_I18N_LEGACY_API__: false,
__VUE_I18N_FULL_INSTALL__: false,
__INTLIFY_PROD_DEVTOOLS__: false,
},
css: {
preprocessorOptions: {
less: {
modifyVars: {
// Used for global import to avoid the need to import each style file separately
// reference: Avoid repeated references
hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
// ...generateModifyVars(),
},
javascriptEnabled: true,
},
},
},
// The vite plugin used by the project. The quantity is large, so it is separately extracted and managed
// plugins: createVitePlugins(viteEnv, isBuild),
optimizeDeps: {
// @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
include: [
'@iconify/iconify',
'ant-design-vue/es/locale/zh_CN',
'moment/dist/locale/zh-cn',
'ant-design-vue/es/locale/en_US',
'moment/dist/locale/eu',
],
exclude: ['vue-demi'],
},
};
};
上一章
第二十一章-使用conventional-changelog-cli生成变更记录
下一章
第二十三章-Node的path.resolve方法