feat: demo显示通过 VITE_SHOW_DEMO 控制
This commit is contained in:
parent
39e4fda14f
commit
d17efc5433
3
env/.env
vendored
3
env/.env
vendored
@ -5,7 +5,6 @@ VITE_APP_PORT = 9000
|
||||
VITE_UNI_APPID = 'H5871D791'
|
||||
VITE_WX_APPID = 'wxa2abb91f64032a2b'
|
||||
|
||||
# 不在src里面引用的变量可以不加 VITE_ 前缀
|
||||
# 是否显示DEMO,1-显示,0-不显示,
|
||||
# TODO:通过新增 .env.local 改写
|
||||
SHOW_DEMO=0
|
||||
VITE_SHOW_DEMO=0
|
||||
|
@ -1,5 +1,11 @@
|
||||
import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'
|
||||
import { hideDemoPages } from './vite.config'
|
||||
import path from 'node:path'
|
||||
import { loadEnv } from 'vite'
|
||||
|
||||
// 获取环境变量的范例
|
||||
const env = loadEnv(process.env.NODE_ENV!, path.resolve(process.cwd(), 'env'))
|
||||
// console.log(env)
|
||||
const { VITE_SHOW_DEMO } = env
|
||||
|
||||
export default defineUniPages({
|
||||
globalStyle: {
|
||||
@ -25,42 +31,44 @@ export default defineUniPages({
|
||||
fontSize: '10px',
|
||||
iconWidth: '24px',
|
||||
spacing: '3px',
|
||||
list: hideDemoPages
|
||||
? [
|
||||
{
|
||||
iconPath: 'static/tabbar/home.png',
|
||||
selectedIconPath: 'static/tabbar/homeHL.png',
|
||||
pagePath: 'pages/index/index',
|
||||
text: '首页',
|
||||
},
|
||||
{
|
||||
iconPath: 'static/tabbar/personal.png',
|
||||
selectedIconPath: 'static/tabbar/personalHL.png',
|
||||
pagePath: 'pages/my/index',
|
||||
text: '我的',
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
iconPath: 'static/tabbar/home.png',
|
||||
selectedIconPath: 'static/tabbar/homeHL.png',
|
||||
pagePath: 'pages/index/index',
|
||||
text: '首页',
|
||||
},
|
||||
// 生产环境要注释掉demo,所以分开来写
|
||||
{
|
||||
iconPath: 'static/tabbar/example.png',
|
||||
selectedIconPath: 'static/tabbar/exampleHL.png',
|
||||
pagePath: 'pages/demo/index',
|
||||
text: '示例',
|
||||
},
|
||||
{
|
||||
iconPath: 'static/tabbar/personal.png',
|
||||
selectedIconPath: 'static/tabbar/personalHL.png',
|
||||
pagePath: 'pages/my/index',
|
||||
text: '我的',
|
||||
},
|
||||
],
|
||||
list:
|
||||
VITE_SHOW_DEMO === '1'
|
||||
? [
|
||||
{
|
||||
iconPath: 'static/tabbar/home.png',
|
||||
selectedIconPath: 'static/tabbar/homeHL.png',
|
||||
pagePath: 'pages/index/index',
|
||||
text: '首页',
|
||||
},
|
||||
// 生产环境要注释掉demo,所以分开来写
|
||||
{
|
||||
iconPath: 'static/tabbar/example.png',
|
||||
selectedIconPath: 'static/tabbar/exampleHL.png',
|
||||
pagePath: 'pages/demo/index',
|
||||
text: '示例',
|
||||
},
|
||||
{
|
||||
iconPath: 'static/tabbar/personal.png',
|
||||
selectedIconPath: 'static/tabbar/personalHL.png',
|
||||
pagePath: 'pages/my/index',
|
||||
text: '我的',
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
iconPath: 'static/tabbar/home.png',
|
||||
selectedIconPath: 'static/tabbar/homeHL.png',
|
||||
pagePath: 'pages/index/index',
|
||||
text: '首页',
|
||||
},
|
||||
|
||||
{
|
||||
iconPath: 'static/tabbar/personal.png',
|
||||
selectedIconPath: 'static/tabbar/personalHL.png',
|
||||
pagePath: 'pages/my/index',
|
||||
text: '我的',
|
||||
},
|
||||
],
|
||||
},
|
||||
// 你也可以定义 pages 字段,它具有最高的优先级。
|
||||
pages: [],
|
||||
|
@ -28,12 +28,6 @@ import { visualizer } from 'rollup-plugin-visualizer'
|
||||
// 另外,小程序有主包2M的限制,所以一般图片会放到图片服务器(不放本地),那这个插件就没用,所以在开发h5的时候,使用本地图片才用得到,既然如此那就不装吧
|
||||
// import viteImagemin from 'vite-plugin-imagemin'
|
||||
|
||||
// 微信生产环境、本地真机调试不要demo路由,本地开发可以有;
|
||||
// TODO: 下面2个根据使用条件选一个即可
|
||||
export const hideDemoPages = process.env.UNI_PLATFORM === 'mp-weixin'
|
||||
// export const hideDemoPages =
|
||||
// process.env.UNI_PLATFORM === 'mp-weixin' && process.env.NODE_ENV === 'production'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default ({ command, mode }) => {
|
||||
console.log(mode === process.env.NODE_ENV)
|
||||
@ -48,7 +42,7 @@ export default ({ command, mode }) => {
|
||||
// process.cwd(): 获取当前文件的目录跟地址
|
||||
// loadEnv(): 返回当前环境env文件中额外定义的变量
|
||||
const env = loadEnv(mode, path.resolve(process.cwd(), 'env'))
|
||||
// console.log(env)
|
||||
console.log(env)
|
||||
console.log(process.env.UNI_PLATFORM) // 得到 mp-weixin, h5 等
|
||||
|
||||
return defineConfig({
|
||||
@ -56,9 +50,10 @@ export default ({ command, mode }) => {
|
||||
plugins: [
|
||||
UniPages({
|
||||
// TODO: 生产环境小程序要过滤掉demo(demo里面很多图片,超过2M的包大小)
|
||||
exclude: hideDemoPages
|
||||
? ['**/components/**/**.*', '**/demo/**/**.*']
|
||||
: ['**/components/**/**.*'],
|
||||
exclude:
|
||||
env.VITE_SHOW_DEMO === '1'
|
||||
? ['**/components/**/**.*']
|
||||
: ['**/components/**/**.*', '**/demo/**/**.*'],
|
||||
homePage: 'pages/index/index',
|
||||
subPackages: ['src/pages-sub'],
|
||||
}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user