使用了vue.config.js 配置以后打包一直失败
ERROR Error loading vue.config.js:
[HBuilder] 10:40:52.547 ERROR TypeError: Cannot read properties of undefined (reading 'appid')
[HBuilder] 10:40:52.557 TypeError: Cannot read properties of undefined (reading 'appid')
- 发布:2024-08-08 10:42
- 更新:2024-12-03 11:58
- 阅读:168
{
"name" : "uniapp-test",
"appid" : "UNIC62A409",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
/ 5+App特有相关 /
"app-plus" : {
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
/ 模块配置 /
"modules" : {},
/ 应用发布信息 /
"distribute" : {
/ android打包配置 /
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
/ ios打包配置 /
"ios" : {},
/ SDK配置 /
"sdkConfigs" : {}
}
},
/ 快应用特有相关 /
"quickapp" : {},
/ 小程序特有相关 /
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false
},
"usingComponents" : true
},
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao" : {
"usingComponents" : true
},
"uniStatistics" : {
"enable" : false
},
"vueVersion" : "3"
}
-
import { defineConfig } from 'vite'
// import compression from 'vite-plugin-compression'
export default defineConfig({
plugins:[]
})
-报错
- 4 11:33:52 [vite] Pre-transform error: Failed to resolve import "./App" from "D:/uniapp-test/main.js". Does the file exist?
11:33:52.706 11:33:52 [vite] Internal server error: Failed to resolve import "./App" from "D:/uniapp-test/main.js". Does the file exist?
11:33:52.707 Plugin: vite:import-analysis
11:33:52.707 File: D:/uniapp-test/main.js:1:18
11:33:52.707 1 | import App from './App'
11:33:52.707 | ^
11:33:52.707 2 | console.log(App);
11:33:52.707 3 |
11:33:52.707 at formatError (file:///C:/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:50863:46)
11:33:52.707 at TransformContext.error (file:///C:/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:50857:19)
11:33:52.707 at normalizeUrl (file:///C:/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:66092:33)
11:33:52.707 at async file:///C:/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:66247:47
11:33:52.707 at async Promise.all (index 0)
11:33:52.707 at async TransformContext.transform (file:///C:/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:66168:13)
11:33:52.708 at async Object.transform (file:///C:/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:51172:30)
11:33:52.708 at async loadAndTransform (file:///C:/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:53923:29)
11:33:52.708 at async viteTransformMiddleware (file:///C:/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:63775:32)
w***@163.com (作者)
// 导入fs模块
const fs = require('fs')
// 导入环境变量配置文件
const ENV_CONFIG = require('./config/env.js');
const manifestPath =
${__dirname}/manifest.json
;let Manifest = fs.readFileSync(manifestPath, {
encoding: 'utf-8'
})
function replaceManifest(path, value) {
const arr = path.split('.')
const len = arr.length
const lastItem = arr[len - 1]
}
console.log(process.env)
console.log(ENV_CONFIG.profiles.active)
if(process.env.NODE_ENV=='development'){
process.env.UNI_APP_NAME=process.env.UNI_SCRIPT
}
console.log(ENV_CONFIG.profiles.active)
// 读取环境变量内容
const appid = ENV_CONFIG[ENV_CONFIG.profiles.active].appid
console.log(appid)
if (appid) {
// #ifdef MP-WEIXIN
replaceManifest('mp-weixin.appid',
"${appid}"
)// #endif
// #ifdef MP-ALIPAY
replaceManifest('mp-alipay.appid',
"${appid}"
)// #endif
}
fs.writeFileSync(manifestPath, Manifest, {
flag: 'w'
})
{
"name" : "小程序模板",
"appid" : "UNIC6CF201",
"description" : "1",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
/ 5+App特有相关 /
"app-plus" : {
"usingComponents" : true,
"nvueCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
/ 模块配置 /
"modules" : {},
/ 应用发布信息 /
"distribute" : {
/ android打包配置 /
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
/ ios打包配置 /
"ios" : {},
/ SDK配置 /
"sdkConfigs" : {}
},
"uniStatistics" : {
"enable" : false
}
},
/ 快应用特有相关 /
"quickapp" : {},
/ 小程序特有相关 /
"mp-weixin" : {
"appid": "111",
"setting" : {
"urlCheck" : false,
"minified" : true,
"postcss" : true,
"es6" : true
},
"usingComponents" : true,
"uniStatistics" : {
"enable" : false
},
"optimization" : {
"subpackages" : true
},
"navigateToMiniProgramAppIdList" : [
"wx7a02312af36f26f0"
],
"usingShopPlugin" : true
},
}
2024-08-09 16:09