You've already forked template-MP-ts
Compare commits
21 Commits
053c1cf31f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1dad063be1 | ||
|
|
e690f53b09 | ||
|
|
7db5d23ab8 | ||
|
|
f1faa644fe | ||
|
|
638fd3fef4 | ||
|
|
484177ca92 | ||
|
|
e17c3f82c3 | ||
|
|
df5f525bda | ||
|
|
1139b2b78a | ||
|
|
bf579e2667 | ||
|
|
4894cfa90b | ||
|
|
bf18ed7ae9 | ||
|
|
9d21fc649f | ||
|
|
5e4f5e8a6e | ||
|
|
223e5c8de3 | ||
|
|
63dacdc470 | ||
|
|
af5f192e22 | ||
|
|
563f750801 | ||
|
|
3432b23ff1 | ||
|
|
99de26a28b | ||
|
|
1e5fd58a65 |
1
.env
1
.env
@@ -2,3 +2,4 @@ VITE_BASE_URL= #接口地址
|
|||||||
VITE_ASSETSURL=https://cdn.vrupup.com/s/1598/assets/ #资源地址
|
VITE_ASSETSURL=https://cdn.vrupup.com/s/1598/assets/ #资源地址
|
||||||
VITE_APPID=wx9cb717d8151d8486 #小程序APPID
|
VITE_APPID=wx9cb717d8151d8486 #小程序APPID
|
||||||
VITE_UNI_APPID=_UNI_8842336 #UNI-APPID
|
VITE_UNI_APPID=_UNI_8842336 #UNI-APPID
|
||||||
|
VITE_LIBVERSION=3.0.0 #微信小程序基础库
|
||||||
@@ -7,5 +7,5 @@
|
|||||||
description = "分析您的更改并创建有意义的提交消息"
|
description = "分析您的更改并创建有意义的提交消息"
|
||||||
|
|
||||||
prompt = """
|
prompt = """
|
||||||
我会分析您的更改并创建一条有意义的提交消息。提交前,我会验证以下事项:构建通过(如果存在构建命令)、测试通过(如果存在测试命令)、Linter 通过(如果存在 lint 命令)、更改的文件中没有明显错误。我会分析更改,以确定修改了哪些文件、更改的性质(功能、修复、重构等)以及受影响的范围/组件。基于分析结果,我会创建一条常规的提交消息,其中包含类型(功能|修复|文档|样式|重构|测试|杂项)、范围(受影响的组件或区域)、主题(用现在时清晰描述)和正文(如果需要,说明更改的原因)。
|
我会分析您的更改并创建一条有意义的提交消息并使用简单的git命令进行提交更改。我会分析更改,以确定修改了哪些文件、更改的性质(功能、修复、重构等)以及受影响的范围/组件。基于分析结果、以及遵循项目的IFLOW上下文中的提交规范,我会创建一条常规的中文提交消息,其中包含类型(新增|修复|文档|优化|其他)、主题(用现在时清晰描述)。
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
{
|
{
|
||||||
|
"language": "zh-CN",
|
||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
"Framelink Figma MCP": {
|
"bing-cn-mcp": {
|
||||||
"description": "为AI编程工具提供Figma设计文件访问能力,支持获取设计数据和下载图像资源,帮助实现设计到代码的一键转换。",
|
"description": "MCP 服务器,提供中文必应搜索结果抓取和网页内容抓取功能,支持中文搜索",
|
||||||
"command": "npx",
|
"command": "npx",
|
||||||
"args": ["-y", "@iflow-mcp/figma-developer-mcp@0.5.0", "--stdio"],
|
"args": ["-y", "@iflow-mcp/bing-cn-mcp"],
|
||||||
"env": {
|
"env": {
|
||||||
"FIGMA_API_KEY": ""
|
"USER_AGENT": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"playwright": {
|
"chrome-devtools": {
|
||||||
|
"description": "Chrome浏览器自动化工具,支持页面操作、性能分析、网络监控等功能",
|
||||||
"command": "npx",
|
"command": "npx",
|
||||||
"args": ["@playwright/mcp@latest"]
|
"args": ["-y", "@iflow-mcp/chrome-devtools-mcp"]
|
||||||
},
|
},
|
||||||
"context7": {
|
"context7": {
|
||||||
"description": "为开发者提供最新技术文档和代码示例的智能检索服务,支持库搜索和文档获取功能",
|
"description": "为开发者提供最新技术文档和代码示例的智能检索服务,支持库搜索和文档获取功能",
|
||||||
@@ -22,15 +24,6 @@
|
|||||||
"command": "npx",
|
"command": "npx",
|
||||||
"args": ["-y", "@iflow-mcp/fetch@1.0.2"]
|
"args": ["-y", "@iflow-mcp/fetch@1.0.2"]
|
||||||
},
|
},
|
||||||
"server-puppeteer": {
|
|
||||||
"description": "基于Puppeteer的浏览器自动化工具,支持页面导航、截图、元素操作和JavaScript执行等功能",
|
|
||||||
"command": "npx",
|
|
||||||
"args": ["-y", "@iflow-mcp/server-puppeteer@0.6.2"],
|
|
||||||
"env": {
|
|
||||||
"PUPPETEER_LAUNCH_OPTIONS": "{\"executablePath\":\"C:\\Program Files\\Google\\Chrome\\Application\"}",
|
|
||||||
"ALLOW_DANGEROUS": "{\"executablePath\":\"C:\\Program Files\\Google\\Chrome\\Application\"}"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"math-tools": {
|
"math-tools": {
|
||||||
"description": "提供34个数学运算工具,包含算术运算、统计计算、数据科学和表达式求值功能,支持高精度计算。",
|
"description": "提供34个数学运算工具,包含算术运算、统计计算、数据科学和表达式求值功能,支持高精度计算。",
|
||||||
"command": "npx",
|
"command": "npx",
|
||||||
@@ -54,10 +47,13 @@
|
|||||||
"command": "npx",
|
"command": "npx",
|
||||||
"args": ["-y", "@iflow-mcp/server-filesystem@0.6.2", "E:\\"]
|
"args": ["-y", "@iflow-mcp/server-filesystem@0.6.2", "E:\\"]
|
||||||
},
|
},
|
||||||
"mcp-server-code-runner": {
|
"Framelink Figma MCP": {
|
||||||
"description": "多语言代码执行器,支持35种编程语言的代码片段执行,包括JavaScript、Python、Go、Java等主流语言",
|
"description": "为AI编程工具提供Figma设计文件访问能力,支持获取设计数据和下载图像资源,帮助实现设计到代码的一键转换。",
|
||||||
"command": "npx",
|
"command": "npx",
|
||||||
"args": ["-y", "@iflow-mcp/mcp-server-code-runner"]
|
"args": ["-y", "@iflow-mcp/figma-developer-mcp@0.5.0", "--stdio"],
|
||||||
|
"env": {
|
||||||
|
"FIGMA_API_KEY": ""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"gitlab": {
|
"gitlab": {
|
||||||
"description": "提供GitLab项目管理、文件操作、Issue管理、合并请求等功能的MCP服务器工具集",
|
"description": "提供GitLab项目管理、文件操作、Issue管理、合并请求等功能的MCP服务器工具集",
|
||||||
|
|||||||
47
IFLOW.md
47
IFLOW.md
@@ -1,4 +1,4 @@
|
|||||||
# 项目概述
|
# 项目概述 - IFLOW 上下文
|
||||||
|
|
||||||
这是一个基于 UniApp + Vue3 + TypeScript 的微信小程序项目模板。它提供了一个基础的项目结构和一些常用的工具函数,方便快速开发微信小程序。
|
这是一个基于 UniApp + Vue3 + TypeScript 的微信小程序项目模板。它提供了一个基础的项目结构和一些常用的工具函数,方便快速开发微信小程序。
|
||||||
|
|
||||||
@@ -9,7 +9,8 @@
|
|||||||
* **TypeScript**: JavaScript 的超集,提供类型检查和更好的开发体验。
|
* **TypeScript**: JavaScript 的超集,提供类型检查和更好的开发体验。
|
||||||
* **uView-Plus**: 基于 UniApp 的 UI 组件库。
|
* **uView-Plus**: 基于 UniApp 的 UI 组件库。
|
||||||
* **z-paging**: 一个用于处理分页加载的组件库。
|
* **z-paging**: 一个用于处理分页加载的组件库。
|
||||||
* **Vuex**: 状态管理库。
|
* **Vuex**: 状态管理库,用于统一管理应用状态(登录状态、用户信息等)。
|
||||||
|
* **luch-request**: 基于 Promise 的网络请求库。
|
||||||
|
|
||||||
## 目录结构
|
## 目录结构
|
||||||
|
|
||||||
@@ -25,14 +26,16 @@
|
|||||||
│ └── utils/ # 工具函数
|
│ └── utils/ # 工具函数
|
||||||
│ └── tool.ts # 常用工具函数
|
│ └── tool.ts # 常用工具函数
|
||||||
├── components/ # 公共组件
|
├── components/ # 公共组件
|
||||||
|
├── wxcomponents/ # 微信原生组件
|
||||||
├── lib/ # 第三方库
|
├── lib/ # 第三方库
|
||||||
│ └── luch-request/ # luch-request 网络请求库
|
│ └── luch-request/ # luch-request 网络请求库
|
||||||
├── pages/ # 主包页面
|
├── pages/ # 主包页面
|
||||||
│ └── index/ # 首页
|
│ └── index/ # 首页
|
||||||
│ └── index.vue # 首页页面
|
│ └── index.vue # 首页页面
|
||||||
├── subPages/ # 分包页面
|
├── subPages/ # 分包页面
|
||||||
|
├── static/ # 静态资源文件
|
||||||
|
│ └── assets/ # 静态图片资源
|
||||||
├── store/ # 状态管理
|
├── store/ # 状态管理
|
||||||
│ └── index.ts # Vuex store
|
|
||||||
├── uni_modules/ # uni-app 组件
|
├── uni_modules/ # uni-app 组件
|
||||||
│ └── z-paging/ # 分页组件库
|
│ └── z-paging/ # 分页组件库
|
||||||
├── uview-plus/ # uView-Plus 组件库
|
├── uview-plus/ # uView-Plus 组件库
|
||||||
@@ -84,6 +87,7 @@ npm install
|
|||||||
* 方法类函数应该使用 `function` 进行定义。
|
* 方法类函数应该使用 `function` 进行定义。
|
||||||
* 避免出现超过4个以上的 `ref`,超过4个则使用 `reactive`。
|
* 避免出现超过4个以上的 `ref`,超过4个则使用 `reactive`。
|
||||||
* 页面的生命周期需要通过 `@dcloudio/uni-app` 依赖进行按需导入,如(`import { onLoad } from '@dcloudio/uni-app'`)。
|
* 页面的生命周期需要通过 `@dcloudio/uni-app` 依赖进行按需导入,如(`import { onLoad } from '@dcloudio/uni-app'`)。
|
||||||
|
页面的加载、挂载生命周期不要使用 `onMounted` 应该使用 `onLoad`
|
||||||
* 全局变量都集中放置于代码顶部。
|
* 全局变量都集中放置于代码顶部。
|
||||||
* 变量名使用小驼峰命名法。
|
* 变量名使用小驼峰命名法。
|
||||||
* 常量名使用全大写。
|
* 常量名使用全大写。
|
||||||
@@ -91,13 +95,14 @@ npm install
|
|||||||
* 事件类方法命名参考 `handleClick`、`onSelect`。
|
* 事件类方法命名参考 `handleClick`、`onSelect`。
|
||||||
* 变量都应该写有注释说明、类型说明。
|
* 变量都应该写有注释说明、类型说明。
|
||||||
* 所有 `Promise` 类方法使用 `async` `await` 写法,避免出现 `.then` 嵌套,并进行容错、错误抛出处理。
|
* 所有 `Promise` 类方法使用 `async` `await` 写法,避免出现 `.then` 嵌套,并进行容错、错误抛出处理。
|
||||||
|
* 在需要页面跳转、提示、加载、本地存储、或其他功能的时候,优先使用工具函数 `common/utils/tool.ts` 中存在的函数。
|
||||||
* 字符串拼接使用ES6的模板语法。
|
* 字符串拼接使用ES6的模板语法。
|
||||||
* TypeScript规范应遵循项目中已有的风格。
|
* TypeScript规范应遵循项目中已有的风格。
|
||||||
|
|
||||||
## 静态资源
|
## 静态资源
|
||||||
|
|
||||||
* 静态资源变量 `ASSETSURL` 已进行全局暴露,可以在 `<template></template>` 中直接使用。
|
* 静态资源变量 `ASSETSURL` 已进行全局暴露,可以在 `<template></template>` 中直接使用。
|
||||||
* 所有静态资源URL应该使用 `ASSETSURL` 进行拼接,如:`${ASSETSURL}simple.png`。
|
* 所有静态资源URL应该使用 `ASSETSURL` 进行拼接,使用方式为:`${ASSETSURL}simple.png`、`background-image: url($ASSETSURL + 'b23bbf0c4c8e59f88f8fd883cb5d6b27.png')`。
|
||||||
|
|
||||||
## 工具函数 (tool.ts)
|
## 工具函数 (tool.ts)
|
||||||
|
|
||||||
@@ -115,18 +120,48 @@ npm install
|
|||||||
* 包含请求和响应拦截器,用于处理通用逻辑(如错误提示、鉴权等)。
|
* 包含请求和响应拦截器,用于处理通用逻辑(如错误提示、鉴权等)。
|
||||||
* 各业务板块的接口都应存放在 `api/modules` 下,并将单个接口进行导出以便页面按需导入。
|
* 各业务板块的接口都应存放在 `api/modules` 下,并将单个接口进行导出以便页面按需导入。
|
||||||
|
|
||||||
|
## 状态管理 (Vuex)
|
||||||
|
|
||||||
|
* 项目集成了Vuex进行全局状态管理。
|
||||||
|
* 状态管理文件位于 `store/index.ts`。
|
||||||
|
* 使用 `useStore` 钩子在组件中访问状态。
|
||||||
|
|
||||||
## 组件
|
## 组件
|
||||||
|
|
||||||
* 项目集成了 `uView-Plus` 和 `z-paging` 两个组件库。
|
* 项目集成了 `uView-Plus` 和 `z-paging` 两个组件库。
|
||||||
|
* 所有 `uni_modules` 目录中的组件无需导入直接可以进行使用。
|
||||||
* `uView-Plus` 组件已通过 `easycom` 自动导入,可以直接使用,如:`<u-button>`、`<u-icon>`。
|
* `uView-Plus` 组件已通过 `easycom` 自动导入,可以直接使用,如:`<u-button>`、`<u-icon>`。
|
||||||
* 全局组件放在 `components/` 目录下。
|
* 全局组件放在 `components/` 目录下。
|
||||||
* 页面独立组件放在页面根目录下的 `components/`。
|
* 页面独立组件放在页面根目录下的 `components/`。
|
||||||
* 每个组件应该附带 `README.MD` 文档。
|
* 微信的原生组件放在页面根目录下的 `wxcomponents/`,并在使用了组件的对应页面路由配置中添加组件的引用属性 `"usingComponents": { "components": "/wxcomponents/components/components" }`。
|
||||||
* 组件编写应遵循项目中已有的风格。
|
* 组件编写应遵循项目中已有的风格。
|
||||||
|
|
||||||
|
## 分页功能
|
||||||
|
|
||||||
|
* 项目使用 `z-paging` 组件实现分页功能。
|
||||||
|
* 分页组件通过 `v-model` 绑定数据,并使用 `@query` 事件处理数据查询。
|
||||||
|
* 在页面中直接使用 `v-for` 循环渲染数据项,如:`<view class="item" v-for="item in dataList" :key="item.id">`。
|
||||||
|
* 通过 `paging.value?.reload()` 触发分页组件重新加载数据。
|
||||||
|
* 通过 `paging.value?.complete()` 通知分页组件数据加载完成。
|
||||||
|
|
||||||
## 页面
|
## 页面
|
||||||
|
|
||||||
* 页面配置在 `pages.json` 中管理。
|
* 页面配置在 `pages.json` 中管理。
|
||||||
* 主包页面放在 `pages/` 目录下,分包页面放在 `subPages/` 目录下。
|
* 主包页面放在 `pages/` 目录下,分包页面放在 `subPages/` 目录下,如果页面不属于一级页面且没有包含在 `pages.json` 中的 `tabbar`,则应该放置在分包目录下。
|
||||||
* 页面使用 Composition API (setup语法糖) 编写。
|
* 页面使用 Composition API (setup语法糖) 编写。
|
||||||
* 注释、结构规范应遵循项目中已有的风格。
|
* 注释、结构规范应遵循项目中已有的风格。
|
||||||
|
|
||||||
|
## 代码提交规范
|
||||||
|
|
||||||
|
* 提交信息应清晰描述变更内容,如 `修复 搜索功能空值检查` 或 `新增 删除按钮功能`。
|
||||||
|
* 对于功能性的新增或修改,使用 `新增` 前缀。
|
||||||
|
* 对于错误修复,使用 `修复` 前缀。
|
||||||
|
* 对于性能优化、代码重构(既不修复错误也不添加功能),使用 `优化` 前缀。
|
||||||
|
* 对于文档更新,使用 `文档` 前缀。
|
||||||
|
* 提交信息应使用中文。
|
||||||
|
|
||||||
|
## 其他
|
||||||
|
|
||||||
|
* 页面中的分享功能应该使用原生的微信分享功能,通过 `button` 或 `<u-button>` 组件的 `open-type="share"` 属性实现。
|
||||||
|
* 项目使用环境变量管理不同环境的配置,通过 `.env` 文件配置。
|
||||||
|
* Vite配置文件 `vite.config.js` 包含了自定义插件用于在编译时替换 `manifest.json` 中的 appid。
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// 定义内外边距,历遍1-40
|
// 定义内外边距,历遍1-100
|
||||||
@for $i from 0 through 40 {
|
@for $i from 0 through 100 {
|
||||||
// 只要双数和能被5除尽的数
|
// 只要双数和能被5除尽的数
|
||||||
@if $i % 2==0 or $i % 5==0 {
|
@if $i % 2==0 or $i % 5==0 {
|
||||||
// 得出:u-margin-30或者u-m-30
|
// 得出:u-margin-30或者u-m-30
|
||||||
|
|||||||
2
main.ts
2
main.ts
@@ -1,6 +1,7 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
|
import store from './store'
|
||||||
|
|
||||||
// 创建应用实例
|
// 创建应用实例
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
@@ -14,6 +15,7 @@ app.provide('ASSETSURL', ASSETSURL)
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import uView from './uview-plus/index'
|
import uView from './uview-plus/index'
|
||||||
app.use(uView)
|
app.use(uView)
|
||||||
|
app.use(store)
|
||||||
|
|
||||||
// 挂载应用
|
// 挂载应用
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
|||||||
41
pages.json
41
pages.json
@@ -1,22 +1,43 @@
|
|||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
{
|
{
|
||||||
"path": "pages/index/index",
|
"path": "pages/index/index"
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "首页"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"globalStyle": {
|
"subPackages": [
|
||||||
"navigationBarTextStyle": "black",
|
{
|
||||||
"navigationBarTitleText": "uni-app",
|
"root": "subPages",
|
||||||
"navigationBarBackgroundColor": "#F8F8F8",
|
"pages": [
|
||||||
"backgroundColor": "#F8F8F8"
|
{
|
||||||
|
"path": "welcome/index"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tabBar": {
|
||||||
|
"color": "#c3c3c3",
|
||||||
|
"selectedColor": "#454c5c",
|
||||||
|
"backgroundColor": "#ffffff",
|
||||||
|
"borderStyle": "black",
|
||||||
|
"list": [
|
||||||
|
{
|
||||||
|
"pagePath": "pages/index/index",
|
||||||
|
"text": "首页",
|
||||||
|
"iconPath": "static/assets/icon_home.png",
|
||||||
|
"selectedIconPath": "static/assets/icon_home_selected.png"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"easycom": {
|
"easycom": {
|
||||||
"autoscan": true,
|
"autoscan": true,
|
||||||
"custom": {
|
"custom": {
|
||||||
"^u-(.*)": "@/uview-plus/components/u-$1/u-$1.vue"
|
"^u-([^-].*)": "@/uview-plus/components/u-$1/u-$1.vue"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"globalStyle": {
|
||||||
|
"navigationBarTextStyle": "black",
|
||||||
|
"navigationBarTitleText": "miniprogram",
|
||||||
|
"navigationBarBackgroundColor": "#F8F8F8",
|
||||||
|
"backgroundColor": "#F8F8F8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BIN
static/assets/icon_home.png
Normal file
BIN
static/assets/icon_home.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
static/assets/icon_home_selected.png
Normal file
BIN
static/assets/icon_home_selected.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
7
subPages/welcome/index.vue
Normal file
7
subPages/welcome/index.vue
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<template>
|
||||||
|
<div> </div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts"></script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
||||||
@@ -1,36 +1,50 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import uni from '@dcloudio/vite-plugin-uni'
|
import uni from '@dcloudio/vite-plugin-uni'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import { readFileSync, writeFileSync } from 'fs'
|
import { readFileSync, writeFileSync, existsSync, unlinkSync } from 'fs'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
|
|
||||||
// 自定义插件:替换 manifest.json 中的 appid
|
// 自定义插件:替换 manifest.json 中的 appid
|
||||||
|
// 仅在通过HBuilder首次编译时执行,避免热重载时重复执行导致内存占用高
|
||||||
function replaceManifestAppid() {
|
function replaceManifestAppid() {
|
||||||
return {
|
return {
|
||||||
name: 'replace-manifest-appid',
|
name: 'replace-manifest-appid',
|
||||||
buildStart() {
|
buildStart() {
|
||||||
|
// 检查是否通过HBuilder编译
|
||||||
|
// 检查是否已经执行过插件
|
||||||
|
const manifestUpdatedFlag = resolve(__dirname, '.manifest-updated')
|
||||||
|
const isFirstCompile = !existsSync(manifestUpdatedFlag)
|
||||||
|
|
||||||
|
// 仅首次编译时执行
|
||||||
|
if (!isFirstCompile) {
|
||||||
|
console.log('跳过 manifest appid 更新(已执行过首次编译)')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 获取环境变量,明确指定路径为项目根目录
|
// 获取环境变量,明确指定路径为项目根目录
|
||||||
dotenv.config({ path: resolve(__dirname, '.env') })
|
dotenv.config({ path: resolve(__dirname, '.env') })
|
||||||
const appid = process.env.VITE_APPID
|
const appid = process.env.VITE_APPID
|
||||||
const uni_appId = process.env.VITE_UNI_APPID
|
const uni_appId = process.env.VITE_UNI_APPID
|
||||||
|
const libVersion = process.env.VITE_LIBVERSION || '3.0.0'
|
||||||
|
|
||||||
if (appid && uni_appId) {
|
if (appid && uni_appId) {
|
||||||
// 读取 manifest.json 文件
|
// 读取 manifest.json 文件
|
||||||
const manifestPath = resolve(__dirname, 'manifest.json')
|
const manifestPath = resolve(__dirname, 'manifest.json')
|
||||||
let manifestContent = readFileSync(manifestPath, 'utf-8')
|
let manifestContent = readFileSync(manifestPath, 'utf-8')
|
||||||
|
|
||||||
// 解析 JSON
|
// 解析 JSON
|
||||||
const manifest = JSON.parse(manifestContent)
|
const manifest = JSON.parse(manifestContent)
|
||||||
|
|
||||||
// 替换
|
// 替换
|
||||||
manifest.appid = uni_appId
|
manifest.appid = uni_appId
|
||||||
|
|
||||||
if (manifest['mp-weixin']) {
|
if (manifest['mp-weixin']) {
|
||||||
manifest['mp-weixin'].appid = appid
|
manifest['mp-weixin'].appid = appid
|
||||||
|
manifest['mp-weixin'].libVersion = libVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// 写回文件
|
// 写回文件
|
||||||
writeFileSync(manifestPath, JSON.stringify(manifest, null, 4))
|
writeFileSync(manifestPath, JSON.stringify(manifest, null, 4))
|
||||||
|
// 创建标记文件,表示已执行过插件
|
||||||
|
writeFileSync(manifestUpdatedFlag, 'Manifest updated by HBuilder first compile')
|
||||||
console.log(`Manifest appid 已更新为: ${uni_appId}`)
|
console.log(`Manifest appid 已更新为: ${uni_appId}`)
|
||||||
console.log(`Manifest mp-weixin appid 已更新为: ${appid}`)
|
console.log(`Manifest mp-weixin appid 已更新为: ${appid}`)
|
||||||
} else {
|
} else {
|
||||||
@@ -40,8 +54,22 @@ function replaceManifestAppid() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否通过HBuilder编译,决定是否启用插件
|
||||||
|
const manifestUpdatedFlag = resolve(__dirname, '.manifest-updated')
|
||||||
|
|
||||||
|
if (existsSync(manifestUpdatedFlag)) {
|
||||||
|
unlinkSync(manifestUpdatedFlag)
|
||||||
|
console.log('已清理 manifest 更新标记文件')
|
||||||
|
}
|
||||||
|
|
||||||
|
const plugins = manifestUpdatedFlag ? [replaceManifestAppid(), uni()] : [uni()]
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [replaceManifestAppid(), uni()],
|
plugins,
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@': '/src',
|
||||||
|
},
|
||||||
|
},
|
||||||
build: {
|
build: {
|
||||||
minify: 'terser',
|
minify: 'terser',
|
||||||
terserOptions: {
|
terserOptions: {
|
||||||
|
|||||||
Reference in New Issue
Block a user