Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wychl
uni-app
提交
75e6f5a3
U
uni-app
项目概览
wychl
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
75e6f5a3
编写于
3月 29, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 完善编译到微信小程序插件
上级
26dd6b3e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
103 addition
and
6 deletion
+103
-6
packages/uni-mp-weixin/lib/uni.config.js
packages/uni-mp-weixin/lib/uni.config.js
+3
-2
packages/vue-cli-plugin-uni/commands/build.js
packages/vue-cli-plugin-uni/commands/build.js
+54
-2
packages/vue-cli-plugin-uni/lib/mp/index.js
packages/vue-cli-plugin-uni/lib/mp/index.js
+12
-1
packages/webpack-uni-mp-loader/lib/plugin/index-new.js
packages/webpack-uni-mp-loader/lib/plugin/index-new.js
+34
-1
未找到文件。
packages/uni-mp-weixin/lib/uni.config.js
浏览文件 @
75e6f5a3
...
@@ -27,7 +27,8 @@ module.exports = {
...
@@ -27,7 +27,8 @@ module.exports = {
'
theme.json
'
,
'
theme.json
'
,
'
sitemap.json
'
,
'
sitemap.json
'
,
'
ext.json
'
,
'
ext.json
'
,
'
custom-tab-bar
'
'
custom-tab-bar
'
,
'
plugin.json
'
]
]
const
workers
=
platformOptions
.
workers
const
workers
=
platformOptions
.
workers
workers
&&
copyOptions
.
push
(
workers
)
workers
&&
copyOptions
.
push
(
workers
)
...
@@ -52,4 +53,4 @@ module.exports = {
...
@@ -52,4 +53,4 @@ module.exports = {
})
})
return
copyOptions
return
copyOptions
}
}
}
}
packages/vue-cli-plugin-uni/commands/build.js
浏览文件 @
75e6f5a3
const
path
=
require
(
'
path
'
)
const
path
=
require
(
'
path
'
)
const
fs
=
require
(
'
fs
'
)
const
{
const
{
runByHBuilderX
,
runByHBuilderX
,
...
@@ -43,8 +44,14 @@ module.exports = (api, options) => {
...
@@ -43,8 +44,14 @@ module.exports = (api, options) => {
process
.
env
.
UNI_SUBPACKGE
=
args
.
subpackage
process
.
env
.
UNI_SUBPACKGE
=
args
.
subpackage
}
}
if
(
args
.
plugin
&&
platforms
.
includes
(
process
.
env
.
UNI_PLATFORM
))
{
if
(
args
.
plugin
)
{
process
.
env
.
UNI_MP_PLUGIN
=
args
.
plugin
if
(
process
.
env
.
UNI_PLATFORM
===
'
mp-weixin
'
)
{
process
.
env
.
UNI_MP_PLUGIN
=
args
.
plugin
analysisPluginDir
()
}
else
{
console
.
error
(
'
编译到小程序插件只支持微信小程序
'
)
process
.
exit
(
0
)
}
}
}
require
(
'
./util
'
).
initAutomator
(
args
)
require
(
'
./util
'
).
initAutomator
(
args
)
...
@@ -196,3 +203,48 @@ async function build (args, api, options) {
...
@@ -196,3 +203,48 @@ async function build (args, api, options) {
module
.
exports
.
defaultModes
=
{
module
.
exports
.
defaultModes
=
{
'
uni-build
'
:
process
.
env
.
NODE_ENV
'
uni-build
'
:
process
.
env
.
NODE_ENV
}
}
/**
* 编译到微信小程序插件 文件校验
*/
function
analysisPluginDir
()
{
// plugin.json 是否存在
const
pluginJsonName
=
'
plugin.json
'
const
pluginJsonPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
pluginJsonName
)
if
(
!
fs
.
existsSync
(
pluginJsonPath
))
{
console
.
error
(
`
${
pluginJsonName
}
文件不存在,请检查后重试`
)
process
.
exit
(
0
)
}
const
pluginJson
=
require
(
pluginJsonPath
)
// index.js 入口文件是否存在
process
.
env
.
UNI_MP_PLUGIN_MAIN
=
pluginJson
.
main
const
UNI_MP_PLUGIN_MAIN
=
process
.
env
.
UNI_MP_PLUGIN_MAIN
const
mainFilePath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
UNI_MP_PLUGIN_MAIN
)
if
(
UNI_MP_PLUGIN_MAIN
&&
!
fs
.
existsSync
(
mainFilePath
))
{
console
.
error
(
`
${
UNI_MP_PLUGIN_MAIN
}
入口文件不存在,请检查后重试`
)
process
.
exit
(
0
)
}
// 目前编译到小程序插件,需要在 pages.json 中配置页面,在main.js中引入使用一下组件,因此先不做一下校验
// 配置的路径是否存在
/* const pages = pluginJson.pages || {}
const publicComponents = pluginJson.publicComponents || {}
const allFilesPath = Object.values(pages).map(item => item + '.vue').concat(Object.values(publicComponents).map(item => item + '.vue'))
const inexistenceFiles = []
if (allFilesPath.length) {
allFilesPath.forEach(pagePath => {
const curentPageAbsolutePath = path.resolve(process.env.UNI_INPUT_DIR, pagePath)
if (!fs.existsSync(curentPageAbsolutePath)) {
inexistenceFiles.push(curentPageAbsolutePath)
}
})
}
if (inexistenceFiles.length) {
inexistenceFiles.forEach(path => {
console.error(`${path}文件不存在,请检查后重试`)
})
process.exit(0)
} */
}
packages/vue-cli-plugin-uni/lib/mp/index.js
浏览文件 @
75e6f5a3
...
@@ -156,7 +156,7 @@ module.exports = {
...
@@ -156,7 +156,7 @@ module.exports = {
const
statCode
=
process
.
env
.
UNI_USING_STAT
?
'
import
\'
@dcloudio/uni-stat
\'
;
'
:
''
const
statCode
=
process
.
env
.
UNI_USING_STAT
?
'
import
\'
@dcloudio/uni-stat
\'
;
'
:
''
cons
t
beforeCode
=
'
import
\'
uni-pages
\'
;
'
le
t
beforeCode
=
'
import
\'
uni-pages
\'
;
'
const
plugins
=
[
const
plugins
=
[
new
WebpackUniAppPlugin
(),
new
WebpackUniAppPlugin
(),
...
@@ -168,6 +168,17 @@ module.exports = {
...
@@ -168,6 +168,17 @@ module.exports = {
plugins
.
push
(
new
PreprocessAssetsPlugin
())
plugins
.
push
(
new
PreprocessAssetsPlugin
())
}
}
if
(
process
.
env
.
UNI_MP_PLUGIN
)
{
// 小程序插件入口使用
// packages\webpack-uni-mp-loader\lib\plugin\index-new.js -> addMPPluginRequire
beforeCode
+=
'
wx.__webpack_require__ = __webpack_require__;
'
const
UNI_MP_PLUGIN_MAIN
=
process
.
env
.
UNI_MP_PLUGIN_MAIN
if
(
UNI_MP_PLUGIN_MAIN
)
{
process
.
UNI_ENTRY
[
UNI_MP_PLUGIN_MAIN
.
split
(
'
.
'
)[
0
]]
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
UNI_MP_PLUGIN_MAIN
)
}
}
return
{
return
{
mode
:
process
.
env
.
NODE_ENV
===
'
production
'
?
'
production
'
:
'
development
'
,
mode
:
process
.
env
.
NODE_ENV
===
'
production
'
?
'
production
'
:
'
development
'
,
entry
()
{
entry
()
{
...
...
packages/webpack-uni-mp-loader/lib/plugin/index-new.js
浏览文件 @
75e6f5a3
...
@@ -65,6 +65,37 @@ function addSubPackagesRequire (compilation) {
...
@@ -65,6 +65,37 @@ function addSubPackagesRequire (compilation) {
})
})
}
}
function
addMPPluginRequire
(
compilation
)
{
// 编译到小程序插件 特殊处理入口文件
if
(
process
.
env
.
UNI_MP_PLUGIN
)
{
const
assetsKeys
=
Object
.
keys
(
compilation
.
assets
)
assetsKeys
.
forEach
(
name
=>
{
if
(
name
===
process
.
env
.
UNI_MP_PLUGIN_MAIN
)
{
const
modules
=
compilation
.
modules
const
mainFilePath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
process
.
env
.
UNI_MP_PLUGIN_MAIN
).
replace
(
/
\\
/g
,
'
/
'
)
const
uniModuleId
=
modules
.
find
(
module
=>
module
.
resource
&&
normalizePath
(
module
.
resource
)
===
mainFilePath
).
id
const
newlineIndex
=
compilation
.
assets
[
name
].
source
().
lastIndexOf
(
'
\n
'
)
const
source
=
compilation
.
assets
[
name
].
source
().
substring
(
0
,
newlineIndex
)
+
`\nmodule.exports = wx.__webpack_require__(
${
uniModuleId
}
);\n`
+
compilation
.
assets
[
name
].
source
().
substring
(
newlineIndex
+
1
)
compilation
.
assets
[
name
]
=
{
size
()
{
return
Buffer
.
byteLength
(
source
,
'
utf8
'
)
},
source
()
{
return
source
}
}
}
})
}
}
class
WebpackUniMPPlugin
{
class
WebpackUniMPPlugin
{
apply
(
compiler
)
{
apply
(
compiler
)
{
if
(
!
process
.
env
.
UNI_USING_NATIVE
&&
!
process
.
env
.
UNI_USING_V3_NATIVE
)
{
if
(
!
process
.
env
.
UNI_USING_NATIVE
&&
!
process
.
env
.
UNI_USING_V3_NATIVE
)
{
...
@@ -72,6 +103,8 @@ class WebpackUniMPPlugin {
...
@@ -72,6 +103,8 @@ class WebpackUniMPPlugin {
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
addSubPackagesRequire
(
compilation
)
addSubPackagesRequire
(
compilation
)
addMPPluginRequire
(
compilation
)
generateJson
(
compilation
)
generateJson
(
compilation
)
// app.js,app.wxss
// app.js,app.wxss
...
@@ -110,4 +143,4 @@ class WebpackUniMPPlugin {
...
@@ -110,4 +143,4 @@ class WebpackUniMPPlugin {
}
}
}
}
module
.
exports
=
WebpackUniMPPlugin
module
.
exports
=
WebpackUniMPPlugin
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录