代码拉取完成,页面将自动刷新
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import components from 'unplugin-vue-components/vite'
import banner from 'vite-plugin-banner'
import { createHtmlPlugin } from 'vite-plugin-html'
import { envDir, sourceDir, manualChunks } from './scripts/build'
import pkg from './package.json'
const { resolve } = require('path')
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, envDir)
return {
// 项目根目录、index.html所在目录
// root: resolve(__dirname, './'),
// root: resolve(__dirname, 'src'),
// 静态资源服务目录地址
// publicDir: resolve(__dirname, 'public'),
/**
* 管理环境变量的配置文件存放目录
*/
envDir,
/**
* 项目部署目录路径
* @description 见项目根目录下的 `config` 文件夹说明
*/
base: env.VITE_DEPLOY_BASE_URL,
/**
* 本地开发服务,也可以配置接口代理
* @see https://cn.vitejs.dev/config/#server-proxy
*/
server: {
port: 3078,
// proxy: {
// '/devapi': {
// target: 'http://192.168.10.198',
// changeOrigin: true,
// rewrite: (path) => path.replace(/^\/devapi/, ''),
// },
// },
},
build: {
rollupOptions: {
input: {
projectA: resolve(__dirname, 'index.html'),
projectB: resolve(__dirname, 'admin.html'),
},
output: {
/**
* 如果要加密打包后的文件名,可以启用该项目
*
* @example
* 1. 先安装 md5 依赖 `npm i -D @withtypes/md5`
* 2. 导入本文件 `import md5 from '@withtypes/md5'`
* 3. 将函数里的 `${name}` 修改为 `${md5(name)}`
*/
// chunkFileNames: ({ name }) => {
// return `assets/${name}-[hash].js`
// },
// entryFileNames: ({ name }) => {
// return `assets/${name}-[hash].js`
// },
// assetFileNames: ({ name }) => {
// return `assets/${name}-[hash].[ext]`
// },
/**
* 打包优化,避免全部打包到一个很大的 Chunk 里
* @description 根据包名生成不同的 Chunk 文件,方便按需加载
*/
manualChunks,
},
},
},
resolve: {
/**
* 配置目录别名
* @see https://cn.vitejs.dev/config/shared-options.html#resolve-alias
*
* @example
* 想从 `src/libs/foo` 文件里导入功能:
* 配置 alias 前: `import foo from '../../../libs/foo'`
* 配置 alias 后: `import foo from '@/libs/foo'`
*/
alias: {
'@': sourceDir,
'@projectA': resolve(__dirname, 'src/pages/projectA'),
'@projectB': resolve(__dirname, 'src/pages/projectB'),
// '@projectA': fileURLToPath(
// new URL('./src/pages/projectA', import.meta.url)
// ),
// '@projectB': fileURLToPath(
// new URL('./src/pages/projectB', import.meta.url)
// ),
},
},
css: {
/**
* 包括 `vw` / `rem` 单位转换等
* @see https://cn.vitejs.dev/config/shared-options.html#css-postcss
*
* @example
* 以使用 `vw` 作为移动端适配为例:
* 1. 先安装 postcss 依赖 `npm i -D postcss-px-to-viewport`
* 2. 导入本文件 `import px2vw from 'postcss-px-to-viewport'`
* 3. 取消下面函数的注释即可生效
*/
// postcss: {
// plugins: [
// // 使用 postcss-pxtorem
// // px2rem({
// // propList: ['*'],
// // }),
// // 使用 postcss-px-to-viewport
// // px2vw({
// // viewportWidth: 375,
// // minPixelValue: 1,
// // }),
// ],
// },
},
plugins: [
/**
* 支持 `.vue` 文件的解析
*/
vue(),
/**
* 如果需要支持 `.tsx` 组件,请安装 `@vitejs/plugin-vue-jsx` 这个包
* 并在这里添加一个插件导入 `import vueJsx from '@vitejs/plugin-vue-jsx'`
*/
// vueJsx(),
/**
* 自动导入组件,不用每次都 import
* @see https://github.com/antfu/unplugin-vue-components#configuration
*/
components({
dirs: ['src/components'],
directoryAsNamespace: true,
collapseSamePrefixes: true,
globalNamespaces: [],
extensions: ['vue', 'ts', 'tsx'],
deep: true,
dts: 'src/types/declaration-files/components.d.ts',
}),
/**
* 版权注释
* @see https://github.com/chengpeiquan/vite-plugin-banner#advanced-usage
*/
banner(
[
`/**`,
` * name: ${pkg.name}`,
` * version: v${pkg.version}`,
` * description: ${pkg.description}`,
` * author: ${pkg.author}`,
` */`,
].join('\n')
),
/**
* 为入口文件增加 EJS 模版能力
* @see https://github.com/vbenjs/vite-plugin-html/blob/main/README.zh_CN.md
*/
createHtmlPlugin({
minify: true,
//XXX 单页面配置
// inject: {
// data: {
// appTitle: env.VITE_APP_TITLE,
// appDesc: env.VITE_APP_DESC,
// appKeywords: env.VITE_APP_KEYWORDS,
// },
// },
//XXX 多页应用配置
pages: [
{
entry: 'src/pages/projectA/main.ts',
filename: 'index.html',
template: 'index.html',
injectOptions: {
data: {
appTitle: env.VITE_APP_TITLE,
appDesc: env.VITE_APP_DESC,
appKeywords: env.VITE_APP_KEYWORDS,
},
},
},
{
entry: 'src/pages/projectB/main.ts',
filename: 'admin.html',
template: 'admin.html',
injectOptions: {
data: {
appTitle: env.VITE_APP_TITLE,
appDesc: env.VITE_APP_DESC,
appKeywords: env.VITE_APP_KEYWORDS,
},
},
},
],
}),
],
}
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。