Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
f0f75d5c
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f0f75d5c
编写于
6月 08, 2023
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uts): compiler
上级
ae695f43
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
74 addition
and
54 deletion
+74
-54
packages/uni-cli-shared/lib/uni_modules/uni_modules.js
packages/uni-cli-shared/lib/uni_modules/uni_modules.js
+68
-49
packages/vue-cli-plugin-uni/lib/configure-webpack.js
packages/vue-cli-plugin-uni/lib/configure-webpack.js
+6
-5
未找到文件。
packages/uni-cli-shared/lib/uni_modules/uni_modules.js
浏览文件 @
f0f75d5c
...
...
@@ -3,29 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
parseInject
=
exports
.
parseInject
s
=
exports
.
parseUniExtApis
=
void
0
;
exports
.
parseInjects
=
exports
.
parseUniExtApis
=
void
0
;
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
fs_extra_1
=
__importDefault
(
require
(
"
fs-extra
"
));
const
merge_1
=
require
(
"
merge
"
);
function
parseUniExtApis
(
vite
=
true
)
{
function
parseUniExtApis
(
vite
=
true
,
platform
,
language
=
'
javascript
'
)
{
const
uniModulesDir
=
path_1
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
uni_modules
'
);
if
(
!
fs_extra_1
.
default
.
existsSync
(
uniModulesDir
))
{
return
{};
}
let
platform
=
process
.
env
.
UNI_PLATFORM
;
if
(
platform
===
'
h5
'
)
{
platform
=
'
web
'
;
}
else
if
(
platform
===
'
app-plus
'
)
{
platform
=
'
app
'
;
}
const
injects
=
{};
fs_extra_1
.
default
.
readdirSync
(
uniModulesDir
).
forEach
((
uniModuleDir
)
=>
{
// 必须以 uni- 开头
if
(
!
uniModuleDir
.
startsWith
(
'
uni-
'
))
{
return
;
}
const
pkgPath
=
path_1
.
default
.
resolve
(
uniModulesDir
,
uniModuleDir
,
'
package.json
'
);
const
uniModuleRootDir
=
path_1
.
default
.
resolve
(
uniModulesDir
,
uniModuleDir
);
const
pkgPath
=
path_1
.
default
.
resolve
(
uniModuleRootDir
,
'
package.json
'
);
if
(
!
fs_extra_1
.
default
.
existsSync
(
pkgPath
))
{
return
;
}
...
...
@@ -33,18 +26,7 @@ function parseUniExtApis(vite = true) {
const
exports
=
JSON
.
parse
(
fs_extra_1
.
default
.
readFileSync
(
pkgPath
,
'
utf8
'
))
?.
uni_modules
?.[
'
uni-ext-api
'
];
if
(
exports
)
{
const
curInjects
=
parseInjects
(
vite
,
platform
,
`@/uni_modules/
${
uniModuleDir
}
`
,
exports
);
if
(
platform
===
'
app
'
)
{
Object
.
keys
(
curInjects
).
forEach
((
name
)
=>
{
const
options
=
curInjects
[
name
];
// js 平台禁用了
if
(
Array
.
isArray
(
options
)
&&
options
.
length
===
3
)
{
if
(
options
[
2
]
&&
options
[
2
].
js
===
false
)
{
delete
curInjects
[
name
];
}
}
});
}
const
curInjects
=
parseInjects
(
vite
,
platform
,
language
,
`@/uni_modules/
${
uniModuleDir
}
`
,
uniModuleRootDir
,
exports
);
Object
.
assign
(
injects
,
curInjects
);
}
}
...
...
@@ -74,41 +56,43 @@ exports.parseUniExtApis = parseUniExtApis;
* @param define
* @returns
*/
function
parseInjects
(
vite
=
true
,
platform
,
source
,
exports
=
{})
{
function
parseInjects
(
vite
=
true
,
platform
,
language
,
source
,
uniModuleRootDir
,
exports
=
{})
{
let
rootDefines
=
{};
Object
.
keys
(
exports
).
forEach
((
name
)
=>
{
if
(
name
.
startsWith
(
'
uni
'
))
{
rootDefines
[
name
]
=
exports
[
name
];
}
});
const
platformDefines
=
exports
[
platform
];
// 该平台不支持
if
(
platformDefines
===
false
)
{
return
{};
}
if
(
platformDefines
)
{
rootDefines
=
(
0
,
merge_1
.
recursive
)(
true
,
rootDefines
,
platformDefines
);
}
const
injects
=
{};
for
(
const
key
in
rootDefines
)
{
Object
.
assign
(
injects
,
parseInject
(
vite
,
platform
,
source
,
'
uni
'
,
rootDefines
[
key
]));
if
(
Object
.
keys
(
rootDefines
).
length
)
{
const
hasPlatformFile
=
uniModuleRootDir
?
fs_extra_1
.
default
.
existsSync
(
path_1
.
default
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
'
index.uts
'
))
||
fs_extra_1
.
default
.
existsSync
(
path_1
.
default
.
resolve
(
uniModuleRootDir
,
'
utssdk
'
,
platform
))
:
true
;
for
(
const
key
in
rootDefines
)
{
Object
.
assign
(
injects
,
parseInject
(
vite
,
platform
,
language
,
source
,
'
uni
'
,
rootDefines
[
key
],
hasPlatformFile
));
}
}
return
injects
;
}
exports
.
parseInjects
=
parseInjects
;
function
parseInject
(
vite
=
true
,
platform
,
source
,
globalObject
,
defin
e
)
{
function
parseInject
(
vite
=
true
,
platform
,
language
,
source
,
globalObject
,
define
,
hasPlatformFil
e
)
{
const
injects
=
{};
if
(
define
===
false
)
{
}
else
if
(
typeof
define
===
'
string
'
)
{
// {'uni.getBatteryInfo' : '@dcloudio/uni-getbatteryinfo'}
injects
[
globalObject
+
'
.
'
+
define
]
=
vite
?
source
:
[
source
,
'
default
'
];
if
(
hasPlatformFile
)
{
injects
[
globalObject
+
'
.
'
+
define
]
=
vite
?
source
:
[
source
,
'
default
'
];
}
}
else
if
(
Array
.
isArray
(
define
))
{
// {'uni.getBatteryInfo' : ['@dcloudio/uni-getbatteryinfo','getBatteryInfo]}
define
.
forEach
((
d
)
=>
{
injects
[
globalObject
+
'
.
'
+
d
]
=
[
source
,
d
];
});
if
(
hasPlatformFile
)
{
define
.
forEach
((
d
)
=>
{
injects
[
globalObject
+
'
.
'
+
d
]
=
[
source
,
d
];
});
}
}
else
{
const
keys
=
Object
.
keys
(
define
);
...
...
@@ -118,21 +102,56 @@ function parseInject(vite = true, platform, source, globalObject, define) {
}
else
{
const
defineOptions
=
define
[
d
];
if
(
defineOptions
[
platform
]
!==
false
)
{
if
(
platform
===
'
app
'
)
{
injects
[
globalObject
+
'
.
'
+
d
]
=
[
source
,
defineOptions
.
name
||
d
,
defineOptions
.
app
,
];
}
else
{
const
p
=
platform
===
'
app-android
'
||
platform
===
'
app-ios
'
?
'
app
'
:
platform
;
if
(
!
(
p
in
defineOptions
))
{
if
(
hasPlatformFile
)
{
injects
[
globalObject
+
'
.
'
+
d
]
=
[
source
,
defineOptions
.
name
||
d
];
}
}
else
{
if
(
defineOptions
[
p
]
!==
false
)
{
if
(
p
===
'
app
'
)
{
const
appOptions
=
defineOptions
.
app
;
if
(
isPlainObject
(
appOptions
))
{
if
(
language
===
'
javascript
'
)
{
if
(
appOptions
.
js
===
false
)
{
return
;
}
}
else
if
(
language
===
'
kotlin
'
)
{
if
(
appOptions
.
kotlin
===
false
)
{
return
;
}
}
else
if
(
language
===
'
swift
'
)
{
if
(
appOptions
.
swift
===
false
)
{
return
;
}
}
}
injects
[
globalObject
+
'
.
'
+
d
]
=
[
source
,
defineOptions
.
name
||
d
,
defineOptions
.
app
,
];
}
else
{
injects
[
globalObject
+
'
.
'
+
d
]
=
[
source
,
defineOptions
.
name
||
d
,
];
}
}
}
}
});
}
return
injects
;
}
exports
.
parseInject
=
parseInject
;
const
objectToString
=
Object
.
prototype
.
toString
;
const
toTypeString
=
(
value
)
=>
objectToString
.
call
(
value
);
function
isPlainObject
(
val
)
{
return
toTypeString
(
val
)
===
'
[object Object]
'
;
}
packages/vue-cli-plugin-uni/lib/configure-webpack.js
浏览文件 @
f0f75d5c
...
...
@@ -258,7 +258,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
}
:
patterns
))
const
uniExtApis
=
require
(
'
@dcloudio/uni-cli-shared/lib/uni_modules/uni_modules
'
)
.
parseUniExtApis
(
false
)
.
parseUniExtApis
(
false
,
process
.
env
.
UNI_UTS_PLATFORM
,
'
javascript
'
)
const
keys
=
Object
.
keys
(
uniExtApis
)
if
(
keys
.
length
)
{
plugins
.
push
(
new
webpack
.
ProvidePlugin
(
uniExtApis
))
...
...
@@ -284,7 +284,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
plugins
.
push
(
new
CopyWebpackPlugin
(
CopyWebpackPluginVersion
>
5
?
{
patterns
}
:
patterns
))
}
catch
(
e
)
{
}
}
catch
(
e
)
{}
}
if
(
process
.
UNI_SCRIPT_ENV
&&
Object
.
keys
(
process
.
UNI_SCRIPT_ENV
).
length
)
{
...
...
@@ -383,7 +383,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
dir
:
process
.
env
.
UNI_INPUT_DIR
}))
}
}
catch
(
e
)
{
}
}
catch
(
e
)
{}
const
resolveLoaderAlias
=
{}
const
modules
=
[
'
@vue/cli-plugin-babel
'
,
'
@vue/cli-service
'
]
...
...
@@ -416,7 +416,8 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
if
(
process
.
env
.
UNI_PLATFORM
.
startsWith
(
'
mp
'
))
{
const
BabelRuntimeVersions
=
require
(
'
@babel/runtime/package.json
'
).
version
.
split
(
'
.
'
)
if
(
BabelRuntimeVersions
[
0
]
===
'
7
'
&&
Number
(
BabelRuntimeVersions
[
1
])
>=
18
)
{
alias
[
'
@babel/runtime/regenerator
'
]
=
require
.
resolve
(
'
@dcloudio/vue-cli-plugin-uni/packages/@babel/runtime/regenerator
'
)
alias
[
'
@babel/runtime/regenerator
'
]
=
require
.
resolve
(
'
@dcloudio/vue-cli-plugin-uni/packages/@babel/runtime/regenerator
'
)
}
}
...
...
@@ -448,4 +449,4 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
watchOptions
:
require
(
'
./util
'
).
getWatchOptions
()
},
platformWebpackConfig
)
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录