小程序
小游戏
企业微信
微信支付
扫描小程序码分享
小程序的require函数当前只支持相对路径的文件引用,当目录层级很深时,如果需要引用一个靠近根目录的文件,容易导致路径特别长,例如require("../../../../../../a.js"),希望官方未来能支持在app.json中支持配置alias,用于替换路径中过长的“../”
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
已经支持了https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#resolveAlias
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": true,
"lazyloadPlaceholderEnable": false,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"useIsolateContext": false,
"userConfirmedBundleSwitch": false,
"packNpmManually": true,
"packNpmRelationList": [
{
"packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./miniprogram/"
}
],
"minifyWXSS": true,
"disableUseStrict": false,
"minifyWXML": true,
"showES6CompileOption": false,
"useCompilerPlugins": [
"typescript",
"sass"
"ignoreUploadUnusedFiles": true,
"compileWorklet": true
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"appid": "wx0abe49f1abc7839e",
"libVersion": "2.33.0",
"condition": {},
"srcMiniprogramRoot": "miniprogram/",
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 4
"resolveAlias": {
"@/*": "/*"
利用app.js做绝对路径方式
// in app.js App({ onLaunch() { }, require(path) { return require(`${path}`) }, }) // in page.js const app = getApp() const util = app.require('./utils/util.js');
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
已经支持了https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#resolveAlias
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": true,
"lazyloadPlaceholderEnable": false,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"useIsolateContext": false,
"userConfirmedBundleSwitch": false,
"packNpmManually": true,
"packNpmRelationList": [
{
"packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./miniprogram/"
}
],
"minifyWXSS": true,
"disableUseStrict": false,
"minifyWXML": true,
"showES6CompileOption": false,
"useCompilerPlugins": [
"typescript",
"sass"
],
"ignoreUploadUnusedFiles": true,
"compileWorklet": true
},
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"appid": "wx0abe49f1abc7839e",
"libVersion": "2.33.0",
"condition": {},
"srcMiniprogramRoot": "miniprogram/",
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 4
},
"resolveAlias": {
"@/*": "/*"
}
}
利用app.js做绝对路径方式
// in app.js App({ onLaunch() { }, require(path) { return require(`${path}`) }, }) // in page.js const app = getApp() const util = app.require('./utils/util.js');