diff --git a/config/appid.dev.js b/config/appid.dev.js deleted file mode 100644 index e2cad50..0000000 --- a/config/appid.dev.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - 'mp-toutiao': { - appid: 'ttc690b02d599a28ee01-d', - }, -}; \ No newline at end of file diff --git a/config/appid.prod.js b/config/appid.prod.js deleted file mode 100644 index 3ad14f0..0000000 --- a/config/appid.prod.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - 'mp-toutiao': { - appid: 'ttc690b02d599a28ee01-p', - }, -}; \ No newline at end of file diff --git a/envs/.env.development b/envs/.env.development new file mode 100644 index 0000000..6233ab3 --- /dev/null +++ b/envs/.env.development @@ -0,0 +1,4 @@ +# 接口地址 +VITE_API_BASE=https://api.test.com +# 头条小程序 appid +VITE_TOUTIAO_APPID=ttc690b02d599a28ee01 \ No newline at end of file diff --git a/envs/.env.production b/envs/.env.production new file mode 100644 index 0000000..a855f8a --- /dev/null +++ b/envs/.env.production @@ -0,0 +1,4 @@ +# 接口地址 +VITE_API_BASE=https://api.formal.com +# 头条小程序 appid +VITE_TOUTIAO_APPID=ttc690b02d599a28ee01-p \ No newline at end of file diff --git a/package.json b/package.json index fe93feb..4bd5800 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "dev:mp-kuaishou": "uni -p mp-kuaishou", "dev:mp-lark": "uni -p mp-lark", "dev:mp-qq": "uni -p mp-qq", - "dev:mp-toutiao": "uni -p mp-toutiao --mode dev", - "dev:mp-toutiao-prod": "uni -p mp-toutiao --mode prod", + "dev:mp-toutiao": "uni -p mp-toutiao --mode development", + "pro:mp-toutiao": "uni -p mp-toutiao --mode production", "dev:mp-harmony": "uni -p mp-harmony", "dev:mp-weixin": "uni -p mp-weixin", "dev:mp-xhs": "uni -p mp-xhs", diff --git a/src/App.vue b/src/App.vue index 52dd89d..21ce4d9 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,17 +1,13 @@ - diff --git a/src/manifest.json b/src/manifest.json index f91cb95..feb8483 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,5 +1,5 @@ { - "name" : "", + "name" : "app", "appid" : "", "description" : "", "versionName" : "1.0.0", @@ -63,7 +63,7 @@ "usingComponents" : true }, "mp-toutiao" : { - "appid" : "ttc690b02d599a28ee01-d", + "appid" : "ttc690b02d599a28ee01", "setting" : { "urlCheck" : false }, diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 6ea68cd..70a5acf 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -1,48 +1,14 @@ - + +onLoad(() => {}); - diff --git a/src/static/logo.png b/src/static/logo.png deleted file mode 100644 index b5771e2..0000000 Binary files a/src/static/logo.png and /dev/null differ diff --git a/tools/json-editor.js b/tools/json-editor.js index 8fd7559..6260017 100644 --- a/tools/json-editor.js +++ b/tools/json-editor.js @@ -13,7 +13,7 @@ const path = require('path'); function updateJsonFileField(filePath, fieldPath, newValue, options = {}) { const tabSize = options.tabSize || 2; if (!fs.existsSync(filePath)) { - console.warn(`[json-editor] ⚠️ 文件不存在: ${filePath}`); + console.warn(`[json-editor] 文件不存在: ${filePath}`); return; } try { @@ -21,16 +21,16 @@ function updateJsonFileField(filePath, fieldPath, newValue, options = {}) { parse(raw); // 验证是否为合法 JSONC const edits = modify(raw, fieldPath, newValue, { - formattingOptions: { - insertSpaces: true, - tabSize, - }, + formattingOptions: { + insertSpaces: true, + tabSize, + }, }); const updated = applyEdits(raw, edits); fs.writeFileSync(filePath, updated, 'utf-8'); - console.log(`[json-editor] ✅ ${path.basename(filePath)} -> 修改 ${fieldPath.join('.')} = ${JSON.stringify(newValue)}`); + console.log(`[json-editor] ${path.basename(filePath)} -> 修改 ${fieldPath.join('.')} = ${JSON.stringify(newValue)}`); } catch (err) { - console.error(`[json-editor] ❌ 修改失败: ${err.message}`); + console.error(`[json-editor] 修改失败: ${err.message}`); } } diff --git a/vite.config.js b/vite.config.js index 4924938..df815a6 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,19 +1,22 @@ -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; import uni from '@dcloudio/vite-plugin-uni'; import path from 'path'; import { updateJsonFileField } from './tools/json-editor.js'; // https://vitejs.dev/config/ -export default defineConfig(({ mode }) =>{ - console.log('当前模式:', mode); - const configAppidPath = path.resolve(__dirname, `config/appid.${mode}.js`); - const appidConfig = require(configAppidPath); +/** + * @param {String} mode development/production +*/ +export default defineConfig(({ mode = 'development' }) =>{ + const env = loadEnv(mode, './envs'); + console.log('current mode:', mode); const manifestPath = path.resolve(__dirname, 'src/manifest.json'); - for (const [platform, config] of Object.entries(appidConfig)) { - updateJsonFileField(manifestPath, [platform, 'appid'], config.appid); - } + updateJsonFileField(manifestPath, ['mp-toutiao', 'appid'], env.VITE_TOUTIAO_APPID); return { plugins: [ uni(), ], + define: { + __API__: JSON.stringify(env.VITE_API_BASE), + } } }) \ No newline at end of file