Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
589151b5
U
uni-app
项目概览
DCloud
/
uni-app
2 个月 前同步成功
通知
716
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
589151b5
编写于
10月 17, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(cli): uni ext api
上级
07418505
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
70 addition
and
88 deletion
+70
-88
packages/uni-cli-shared/lib/index.js
packages/uni-cli-shared/lib/index.js
+1
-2
packages/uni-cli-shared/lib/uni_modules-loader.js
packages/uni-cli-shared/lib/uni_modules-loader.js
+0
-8
packages/uni-cli-shared/lib/uni_modules/uni_modules.js
packages/uni-cli-shared/lib/uni_modules/uni_modules.js
+42
-59
packages/vue-cli-plugin-uni/lib/app-plus/index.js
packages/vue-cli-plugin-uni/lib/app-plus/index.js
+2
-3
packages/vue-cli-plugin-uni/lib/configure-webpack.js
packages/vue-cli-plugin-uni/lib/configure-webpack.js
+21
-10
packages/vue-cli-plugin-uni/lib/h5/index.js
packages/vue-cli-plugin-uni/lib/h5/index.js
+2
-3
packages/vue-cli-plugin-uni/lib/mp/index.js
packages/vue-cli-plugin-uni/lib/mp/index.js
+2
-3
未找到文件。
packages/uni-cli-shared/lib/index.js
浏览文件 @
589151b5
...
...
@@ -112,6 +112,5 @@ module.exports = {
getPlatformGlobal
,
getPlatformStat
,
getPlatformPush
,
getPlatformUniCloud
,
uniModulesLoader
:
normalizePath
(
require
.
resolve
(
'
./uni_modules-loader
'
))
getPlatformUniCloud
}
packages/uni-cli-shared/lib/uni_modules-loader.js
已删除
100644 → 0
浏览文件 @
07418505
const
{
genUniModulesExports
}
=
require
(
'
./uni_modules/uni_modules
'
)
module
.
exports
=
function
()
{
this
.
cacheable
&&
this
.
cacheable
()
return
genUniModulesExports
()
}
packages/uni-cli-shared/lib/uni_modules/uni_modules.js
浏览文件 @
589151b5
...
...
@@ -3,17 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
parse
Defines
=
exports
.
parseExports
=
exports
.
genUniModulesExport
s
=
void
0
;
exports
.
parse
Inject
=
exports
.
parseInjects
=
exports
.
parseUniExtApi
s
=
void
0
;
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
fs_extra_1
=
__importDefault
(
require
(
"
fs-extra
"
));
const
merge_1
=
require
(
"
merge
"
);
function
genUniModulesExport
s
()
{
function
parseUniExtApi
s
()
{
const
uniModulesDir
=
path_1
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
uni_modules
'
);
if
(
!
fs_extra_1
.
default
.
existsSync
(
uniModulesDir
))
{
return
''
;
return
{}
;
}
const
importCodes
=
[];
const
assignCodes
=
[];
const
injects
=
{};
fs_extra_1
.
default
.
readdirSync
(
uniModulesDir
).
forEach
((
uniModuleDir
)
=>
{
var
_a
,
_b
;
// 必须以 uni- 开头
...
...
@@ -24,46 +23,14 @@ function genUniModulesExports() {
if
(
!
fs_extra_1
.
default
.
existsSync
(
pkgPath
))
{
return
;
}
const
exports
=
(
_b
=
(
_a
=
JSON
.
parse
(
fs_extra_1
.
default
.
readFileSync
(
pkgPath
,
'
utf8
'
)))
===
null
||
_a
===
void
0
?
void
0
:
_a
.
uni_modules
)
===
null
||
_b
===
void
0
?
void
0
:
_b
.
exports
;
const
exports
=
(
_b
=
(
_a
=
JSON
.
parse
(
fs_extra_1
.
default
.
readFileSync
(
pkgPath
,
'
utf8
'
)))
===
null
||
_a
===
void
0
?
void
0
:
_a
.
uni_modules
)
===
null
||
_b
===
void
0
?
void
0
:
_b
[
'
uni-ext-api
'
]
;
if
(
exports
)
{
const
[
exportsImportCodes
,
exportsAssignCodes
]
=
parseExports
(
process
.
env
.
UNI_PLATFORM
===
'
h5
'
?
'
web
'
:
process
.
env
.
UNI_PLATFORM
,
`@/uni_modules/
${
uniModuleDir
}
`
,
exports
);
importCodes
.
push
(...
exportsImportCodes
);
assignCodes
.
push
(...
exportsAssignCodes
);
Object
.
assign
(
injects
,
parseInjects
(
process
.
env
.
UNI_PLATFORM
===
'
h5
'
?
'
web
'
:
process
.
env
.
UNI_PLATFORM
,
`@/uni_modules/
${
uniModuleDir
}
`
,
exports
));
}
});
if
(
!
importCodes
.
length
)
{
return
''
;
}
return
`
${
importCodes
.
join
(
'
\n
'
)}
${
assignCodes
.
join
(
'
\n
'
)}
`
;
return
injects
;
}
exports
.
genUniModulesExports
=
genUniModulesExports
;
function
parseExports
(
platform
,
source
,
exports
=
{})
{
const
rootDefines
=
{};
Object
.
keys
(
exports
).
forEach
((
name
)
=>
{
if
(
name
.
startsWith
(
'
uni
'
))
{
rootDefines
[
name
]
=
exports
[
name
];
}
});
const
platformDefines
=
exports
[
platform
];
// 该平台不支持
if
(
platformDefines
===
false
)
{
return
[[],
[]];
}
return
parseDefines
(
source
,
(
0
,
merge_1
.
recursive
)(
true
,
rootDefines
,
platformDefines
));
}
exports
.
parseExports
=
parseExports
;
function
parseDefines
(
source
,
defines
=
{})
{
const
importCodes
=
[];
const
assignCodes
=
[];
Object
.
keys
(
defines
).
forEach
((
name
)
=>
{
const
[
defineImportCodes
,
defineAssignCodes
]
=
parseDefine
(
source
,
name
,
defines
[
name
]);
importCodes
.
push
(...
defineImportCodes
);
assignCodes
.
push
(...
defineAssignCodes
);
});
return
[
importCodes
,
assignCodes
];
}
exports
.
parseDefines
=
parseDefines
;
exports
.
parseUniExtApis
=
parseUniExtApis
;
/**
* uni:'getBatteryInfo'
* import getBatteryInfo from '..'
...
...
@@ -85,32 +52,48 @@ exports.parseDefines = parseDefines;
* @param define
* @returns
*/
function
parseDefine
(
source
,
globalObject
,
define
)
{
const
importCodes
=
[];
const
assignCodes
=
[];
if
(
typeof
define
===
'
string
'
)
{
importCodes
.
push
(
`import
${
define
}
from '
${
source
}
'`
);
assignCodes
.
push
(
`
${
globalObject
}
.
${
define
}
=
${
define
}
`
);
function
parseInjects
(
platform
,
source
,
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
(
source
,
'
uni
'
,
rootDefines
[
key
]));
}
return
injects
;
}
exports
.
parseInjects
=
parseInjects
;
function
parseInject
(
source
,
globalObject
,
define
)
{
const
injects
=
{};
if
(
define
===
false
)
{
}
else
if
(
typeof
define
===
'
string
'
)
{
// {'uni.getBatteryInfo' : '@dcloudio/uni-getbatteryinfo'}
injects
[
globalObject
+
'
.
'
+
define
]
=
source
;
}
else
if
(
Array
.
isArray
(
define
))
{
importCodes
.
push
(
`import {
${
define
.
join
(
'
,
'
)}
} from '
${
source
}
'`
);
// {'uni.getBatteryInfo' : ['@dcloudio/uni-getbatteryinfo','getBatteryInfo]}
define
.
forEach
((
d
)
=>
{
assignCodes
.
push
(
`
${
globalObject
}
.
${
d
}
=
${
d
}
`
)
;
injects
[
globalObject
+
'
.
'
+
d
]
=
[
source
,
d
]
;
});
}
else
{
const
keys
=
Object
.
keys
(
define
);
const
specifiers
=
[];
keys
.
forEach
((
d
)
=>
{
if
(
d
!==
define
[
d
])
{
specifiers
.
push
(
`
${
define
[
d
]}
as
${
d
}
`
);
}
else
{
specifiers
.
push
(
d
);
}
assignCodes
.
push
(
`
${
globalObject
}
.
${
d
}
=
${
d
}
`
);
injects
[
globalObject
+
'
.
'
+
d
]
=
[
source
,
define
[
d
]];
});
importCodes
.
push
(
`import {
${
specifiers
.
join
(
'
,
'
)}
} from '
${
source
}
'`
);
}
return
[
importCodes
,
assignCodes
]
;
return
injects
;
}
exports
.
parseInject
=
parseInject
;
packages/vue-cli-plugin-uni/lib/app-plus/index.js
浏览文件 @
589151b5
...
...
@@ -5,8 +5,7 @@ const {
getMainEntry
,
getPlatformStat
,
getPlatformPush
,
getPlatformUniCloud
,
uniModulesLoader
getPlatformUniCloud
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
vueLoader
=
require
(
'
@dcloudio/uni-cli-shared/lib/vue-loader
'
)
...
...
@@ -66,7 +65,7 @@ const v3 = {
const
pushCode
=
getPlatformPush
()
const
uniCloudCode
=
getPlatformUniCloud
()
const
beforeCode
=
`import 'uni-pages';import '
${
uniModulesLoader
}
!';`
const
beforeCode
=
'
import
\'
uni-pages
\'
;
'
if
(
!
webpackConfig
.
optimization
)
{
webpackConfig
.
optimization
=
{}
}
...
...
packages/vue-cli-plugin-uni/lib/configure-webpack.js
浏览文件 @
589151b5
...
...
@@ -230,7 +230,10 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
webpackConfig
.
resolve
.
modules
=
webpackConfig
.
resolve
.
modules
.
filter
(
module
=>
module
!==
'
node_modules
'
)
}
const
plugins
=
[]
const
plugins
=
[
new
webpack
.
ProvidePlugin
(
require
(
'
@dcloudio/uni-cli-shared/lib/uni_modules/uni_modules
'
)
.
parseUniExtApis
())
]
const
isAppView
=
process
.
env
.
UNI_PLATFORM
===
'
app-plus
'
&&
vueOptions
.
pluginOptions
&&
...
...
@@ -239,7 +242,9 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
if
(
!
isAppView
)
{
// app-plus view不需要copy
const
patterns
=
getCopyWebpackPluginOptions
(
manifestPlatformOptions
,
vueOptions
)
plugins
.
push
(
new
CopyWebpackPlugin
(
CopyWebpackPluginVersion
>
5
?
{
patterns
}
:
patterns
))
plugins
.
push
(
new
CopyWebpackPlugin
(
CopyWebpackPluginVersion
>
5
?
{
patterns
}
:
patterns
))
}
if
(
!
process
.
env
.
UNI_SUBPACKGE
||
!
process
.
env
.
UNI_MP_PLUGIN
)
{
try
{
...
...
@@ -258,8 +263,10 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
return
''
}
}]
plugins
.
push
(
new
CopyWebpackPlugin
(
CopyWebpackPluginVersion
>
5
?
{
patterns
}
:
patterns
))
}
catch
(
e
)
{
}
plugins
.
push
(
new
CopyWebpackPlugin
(
CopyWebpackPluginVersion
>
5
?
{
patterns
}
:
patterns
))
}
catch
(
e
)
{}
}
if
(
process
.
UNI_SCRIPT_ENV
&&
Object
.
keys
(
process
.
UNI_SCRIPT_ENV
).
length
)
{
...
...
@@ -309,7 +316,8 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
})
}
if
(
process
.
env
.
NODE_ENV
===
'
development
'
||
(
process
.
env
.
NODE_ENV
===
'
production
'
&&
process
.
env
.
SOURCEMAP
===
'
true
'
))
{
if
(
process
.
env
.
NODE_ENV
===
'
development
'
||
(
process
.
env
.
NODE_ENV
===
'
production
'
&&
process
.
env
.
SOURCEMAP
===
'
true
'
))
{
const
sourceMap
=
require
(
'
@dcloudio/uni-cli-shared/lib/source-map
'
)
let
isAppService
=
false
if
(
...
...
@@ -331,7 +339,9 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
noSources
:
true
,
append
:
false
}
if
(
isInHBuilderX
&&
process
.
env
.
SOURCEMAP_PATH
)
{
sourceMapOptions
.
filename
=
process
.
env
.
SOURCEMAP_PATH
}
if
(
isInHBuilderX
&&
process
.
env
.
SOURCEMAP_PATH
)
{
sourceMapOptions
.
filename
=
process
.
env
.
SOURCEMAP_PATH
}
if
(
useEvalSourceMap
||
useSourceMap
)
{
plugins
.
push
(
sourceMap
.
createSourceMapDevToolPlugin
(
!
sourceMapOptions
.
filename
,
sourceMapOptions
))
}
...
...
@@ -339,7 +349,8 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
if
(
useEvalSourceMap
)
{
plugins
.
push
(
sourceMap
.
createEvalSourceMapDevToolPlugin
())
}
else
if
(
useSourceMap
)
{
plugins
.
push
(
sourceMap
.
createSourceMapDevToolPlugin
(
process
.
env
.
UNI_PLATFORM
===
'
mp-weixin
'
||
process
.
env
.
UNI_PLATFORM
===
'
mp-toutiao
'
))
plugins
.
push
(
sourceMap
.
createSourceMapDevToolPlugin
(
process
.
env
.
UNI_PLATFORM
===
'
mp-weixin
'
||
process
.
env
.
UNI_PLATFORM
===
'
mp-toutiao
'
))
}
}
}
...
...
packages/vue-cli-plugin-uni/lib/h5/index.js
浏览文件 @
589151b5
...
...
@@ -7,8 +7,7 @@ const {
getH5Options
,
getPlatformStat
,
getPlatformPush
,
getPlatformUniCloud
,
uniModulesLoader
getPlatformUniCloud
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
...
...
@@ -104,7 +103,7 @@ module.exports = {
}
catch
(
e
)
{}
const
beforeCode
=
(
useBuiltIns
===
'
entry
'
?
'
import
\'
@babel/polyfill
\'
;
'
:
''
)
+
`import 'uni-pages';import 'uni-
${
process
.
env
.
UNI_PLATFORM
}
';
import '
${
uniModulesLoader
}
!';
`
`import 'uni-pages';import 'uni-
${
process
.
env
.
UNI_PLATFORM
}
';`
return
{
resolve
:
{
...
...
packages/vue-cli-plugin-uni/lib/mp/index.js
浏览文件 @
589151b5
...
...
@@ -9,8 +9,7 @@ const {
getPlatformCssnano
,
getPlatformStat
,
getPlatformPush
,
getPlatformUniCloud
,
uniModulesLoader
getPlatformUniCloud
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
WebpackUniAppPlugin
=
require
(
'
../../packages/webpack-uni-app-loader/plugin/index
'
)
...
...
@@ -182,7 +181,7 @@ module.exports = {
const
pushCode
=
getPlatformPush
()
const
uniCloudCode
=
getPlatformUniCloud
()
let
beforeCode
=
`import 'uni-pages';import '
${
uniModulesLoader
}
!';`
let
beforeCode
=
'
import
\'
uni-pages
\'
;
'
const
plugins
=
[
new
WebpackUniAppPlugin
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录