Commit 06cc4871 by zhangxingmin

push

parent 844bd15d
import App from './App.vue'; // main.js
// #ifndef VUE3
import Vue from 'vue' import Vue from 'vue'
import App from './App.vue'
// 确保 App 组件的类型正确
App.mpType = 'app' App.mpType = 'app'
// 创建 Vue 实例
const app = new Vue({ const app = new Vue({
...App render: h => h(App)
}) })
app.$mount()
// #endif
// #ifdef VUE3 // 挂载应用
// import { createSSRApp } from 'vue' app.$mount()
// export function createApp() {
// const app = createSSRApp(App)
// return {
// app
// }
// }
// #endif
//#ifdef H5 // H5 环境下设置 firstEntryUrl
window.sessionStorage.setItem('firstEntryUrl',window.location.href.split('#')[0]) if (process.env.VUE_APP_PLATFORM === 'h5') {
// #endif window.sessionStorage.setItem('firstEntryUrl', window.location.href.split('#')[0])
}
...@@ -3,41 +3,71 @@ import { createVuePlugin } from 'vite-plugin-vue2' ...@@ -3,41 +3,71 @@ import { createVuePlugin } from 'vite-plugin-vue2'
import path from 'path' import path from 'path'
export default defineConfig({ export default defineConfig({
// 路径前缀,与 Nginx 配置匹配 // 根路径配置,与 Nginx 保持一致
base: '/', base: '/',
plugins: [createVuePlugin()], plugins: [
// 配置 Vue 2 插件
createVuePlugin({
vueTemplateOptions: {
compilerOptions: {
// 针对 Vue 2 的模板编译选项
whitespace: 'condense'
}
}
})
],
resolve: { resolve: {
extensions: ['.vue', '.js', '.ts', '.json'], extensions: ['.vue', '.js', '.ts', '.json'],
alias: { alias: {
'@': path.resolve(__dirname), // 指向 src 目录(如果你的项目结构有 src 目录)
'@api': path.resolve(__dirname, 'api') '@': path.resolve(__dirname, 'src'),
'@api': path.resolve(__dirname, 'api'),
// 确保 Vue 2 正确解析
'vue': 'vue/dist/vue.runtime.common.js'
} }
}, },
// // 开发服务器配置 // 开发服务器配置
// server: { server: {
// port: 8080, port: 8080,
// proxy: { proxy: {
// // 代理后端 API 请求 // 代理后端 API 请求
// '/cffpApi': { '/cffpApi': {
// target: 'http://localhost:8080', target: 'http://localhost:8080', // 修改为实际后端地址
// changeOrigin: true, changeOrigin: true,
// rewrite: (path) => path.replace(/^\/cffpApi/, '') rewrite: (path) => path.replace(/^\/cffpApi/, '')
// } }
// } }
// }, },
build: { build: {
outDir: 'dist', // 输出到 dist 根目录(而非 dist/cffp) outDir: 'dist',
assetsDir: 'assets', assetsDir: 'assets',
// 生成 manifest 文件,便于追踪资源
manifest: true,
// 压缩代码
minify: 'terser',
rollupOptions: { rollupOptions: {
output: { output: {
// 自定义输出文件名
entryFileNames: 'assets/[name].[hash].js', entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'assets/[name].[hash].js', chunkFileNames: 'assets/[name].[hash].js',
assetFileNames: 'assets/[name].[hash].[ext]' assetFileNames: 'assets/[name].[hash].[ext]',
// 手动分割代码
manualChunks(id) {
if (id.includes('node_modules')) {
return 'vendor'; // 将第三方依赖打包到 vendor
}
}
} }
} }
},
// 生产环境移除 console
esbuild: {
drop: ['console', 'debugger']
} }
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment