Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
27ededb4
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
27ededb4
编写于
8月 28, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(cli): support pages.js #450
上级
cbb0521a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
93 addition
and
21 deletion
+93
-21
packages/uni-cli-shared/lib/pages.js
packages/uni-cli-shared/lib/pages.js
+24
-6
packages/webpack-uni-mp-loader/lib/plugin/index-new.js
packages/webpack-uni-mp-loader/lib/plugin/index-new.js
+22
-6
packages/webpack-uni-mp-loader/lib/plugin/index.js
packages/webpack-uni-mp-loader/lib/plugin/index.js
+22
-6
packages/webpack-uni-pages-loader/lib/index-new.js
packages/webpack-uni-pages-loader/lib/index-new.js
+12
-1
packages/webpack-uni-pages-loader/lib/index.js
packages/webpack-uni-pages-loader/lib/index.js
+13
-2
未找到文件。
packages/uni-cli-shared/lib/pages.js
浏览文件 @
27ededb4
...
...
@@ -35,8 +35,8 @@ function getPagesJson () {
return
processPagesJson
(
getJson
(
'
pages.json
'
,
true
))
}
function
parsePagesJson
(
content
)
{
return
processPagesJson
(
parseJson
(
content
,
true
))
function
parsePagesJson
(
content
,
loader
)
{
return
processPagesJson
(
parseJson
(
content
,
true
)
,
loader
)
}
function
filterPages
(
pages
=
[],
root
)
{
...
...
@@ -48,7 +48,25 @@ function filterPages (pages = [], root) {
}
}
function
processPagesJson
(
pagesJson
)
{
const
pagesJsonJsFileName
=
'
pages.js
'
function
processPagesJson
(
pagesJson
,
loader
=
{
addDependency
:
function
()
{}
})
{
const
pagesJsonJsPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
pagesJsonJsFileName
)
if
(
fs
.
existsSync
(
pagesJsonJsPath
))
{
delete
require
.
cache
[
pagesJsonJsPath
]
const
pagesJsonJsFn
=
require
(
pagesJsonJsPath
)
if
(
typeof
pagesJsonJsFn
===
'
function
'
)
{
pagesJson
=
pagesJsonJsFn
(
pagesJson
,
loader
)
if
(
!
pagesJson
)
{
console
.
error
(
`
${
pagesJsonJsFileName
}
必须返回一个 json 对象`
)
}
}
else
{
console
.
error
(
`
${
pagesJsonJsFileName
}
必须导出 function`
)
}
}
let
uniNVueEntryPagePath
if
(
pagesJson
.
pages
&&
pagesJson
.
pages
.
length
)
{
// 如果首页是 nvue
if
(
isNVuePage
(
pagesJson
.
pages
[
0
]))
{
...
...
@@ -86,7 +104,7 @@ function isNVuePage (page, root = '') {
}
function
isValidPage
(
page
,
root
=
''
)
{
if
(
typeof
page
===
'
string
'
)
{
// 不合法的配置
if
(
typeof
page
===
'
string
'
)
{
// 不合法的配置
console
.
warn
(
`
${
page
}
配置错误, 已被忽略, 查看文档: https://uniapp.dcloud.io/collocation/pages?id=pages`
)
return
false
}
...
...
@@ -193,7 +211,6 @@ function parseEntry (pagesJson) {
process
.
UNI_NVUE_ENTRY
=
{}
if
(
process
.
env
.
UNI_USING_NATIVE
)
{
// TODO 考虑 pages.json.js
process
.
UNI_NVUE_ENTRY
[
'
app-config
'
]
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
pages.json
'
)
process
.
UNI_NVUE_ENTRY
[
'
app-service
'
]
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
getMainEntry
())
}
...
...
@@ -231,5 +248,6 @@ module.exports = {
parsePages
,
parseEntry
,
getPagesJson
,
parsePagesJson
parsePagesJson
,
pagesJsonJsFileName
}
packages/webpack-uni-mp-loader/lib/plugin/index-new.js
浏览文件 @
27ededb4
...
...
@@ -6,6 +6,10 @@ const {
normalizePath
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
pagesJsonJsFileName
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/pages
'
)
const
generateApp
=
require
(
'
./generate-app
'
)
const
generateJson
=
require
(
'
./generate-json
'
)
const
generateComponent
=
require
(
'
./generate-component
'
)
...
...
@@ -43,7 +47,8 @@ function addSubPackagesRequire (compilation) {
name
.
indexOf
(
root
)
===
0
&&
name
!==
subPackageVendorPath
)
{
const
source
=
`require('
${
normalizePath
(
path
.
relative
(
path
.
dirname
(
name
),
subPackageVendorPath
))}
');`
+
const
source
=
`require('
${
normalizePath
(
path
.
relative
(
path
.
dirname
(
name
),
subPackageVendorPath
))}
');`
+
compilation
.
assets
[
name
].
source
()
compilation
.
assets
[
name
]
=
{
...
...
@@ -82,11 +87,22 @@ class WebpackUniMPPlugin {
})
compiler
.
hooks
.
invalid
.
tap
(
'
webpack-uni-mp-invalid
'
,
(
fileName
,
changeTime
)
=>
{
if
(
fileName
&&
typeof
fileName
===
'
string
'
&&
path
.
basename
(
fileName
)
===
'
pages.json
'
)
{
// 重新解析 entry
try
{
parseEntry
()
}
catch
(
e
)
{
console
.
error
(
e
)
if
(
fileName
&&
typeof
fileName
===
'
string
'
)
{
// 重新解析 entry
const
basename
=
path
.
basename
(
fileName
)
const
deps
=
process
.
UNI_PAGES_DEPS
||
new
Set
()
if
(
basename
===
'
pages.json
'
||
basename
===
pagesJsonJsFileName
||
deps
.
has
(
normalizePath
(
fileName
))
)
{
try
{
parseEntry
()
}
catch
(
e
)
{
console
.
error
(
e
)
}
}
}
})
...
...
packages/webpack-uni-mp-loader/lib/plugin/index.js
浏览文件 @
27ededb4
...
...
@@ -2,9 +2,14 @@ const path = require('path')
const
{
md5
,
parseEntry
parseEntry
,
normalizePath
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
pagesJsonJsFileName
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/pages
'
)
const
{
getPages
,
getSubPages
,
...
...
@@ -93,11 +98,22 @@ class WebpackUniMPPlugin {
})
compiler
.
hooks
.
invalid
.
tap
(
'
webpack-uni-mp-invalid
'
,
(
fileName
,
changeTime
)
=>
{
if
(
fileName
&&
typeof
fileName
===
'
string
'
&&
path
.
basename
(
fileName
)
===
'
pages.json
'
)
{
// 重新解析 entry
try
{
parseEntry
()
}
catch
(
e
)
{
console
.
error
(
e
)
if
(
fileName
&&
typeof
fileName
===
'
string
'
)
{
// 重新解析 entry
const
basename
=
path
.
basename
(
fileName
)
const
deps
=
process
.
UNI_PAGES_DEPS
||
new
Set
()
if
(
basename
===
'
pages.json
'
||
basename
===
pagesJsonJsFileName
||
deps
.
has
(
normalizePath
(
fileName
))
)
{
try
{
parseEntry
()
}
catch
(
e
)
{
console
.
error
(
e
)
}
}
}
})
...
...
packages/webpack-uni-pages-loader/lib/index-new.js
浏览文件 @
27ededb4
...
...
@@ -14,6 +14,10 @@ const {
updateProjectJson
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/cache
'
)
const
{
pagesJsonJsFileName
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/pages
'
)
const
parseStyle
=
require
(
'
./util
'
).
parseStyle
// 将开发者手动设置的 usingComponents 调整名称,方便与自动解析到的 usingComponents 做最后合并
...
...
@@ -28,12 +32,19 @@ function renameUsingComponents (jsonObj) {
module
.
exports
=
function
(
content
)
{
this
.
cacheable
&&
this
.
cacheable
()
const
pagesJsonJsPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
pagesJsonJsFileName
)
const
manifestJsonPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
manifest.json
'
)
const
manifestJson
=
parseManifestJson
(
fs
.
readFileSync
(
manifestJsonPath
,
'
utf8
'
))
this
.
addDependency
(
pagesJsonJsPath
)
this
.
addDependency
(
manifestJsonPath
)
const
pagesJson
=
parsePagesJson
(
content
)
const
pagesJson
=
parsePagesJson
(
content
,
{
addDependency
:
(
file
)
=>
{
(
process
.
UNI_PAGES_DEPS
||
(
process
.
UNI_PAGES_DEPS
=
new
Set
())).
add
(
normalizePath
(
file
))
this
.
addDependency
(
file
)
}
})
// TODO 与 usingComponents 放在一块读取设置
if
(
manifestJson
.
transformPx
===
false
)
{
process
.
UNI_TRANSFORM_PX
=
false
...
...
packages/webpack-uni-pages-loader/lib/index.js
浏览文件 @
27ededb4
...
...
@@ -13,6 +13,10 @@ const {
getPagesJson
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/cache
'
)
const
{
pagesJsonJsFileName
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/pages
'
)
const
parseStyle
=
require
(
'
./util
'
).
parseStyle
const
emitFileCaches
=
{}
...
...
@@ -25,7 +29,7 @@ function checkEmitFile (filePath, jsonObj, changedEmitFiles) {
}
}
module
.
exports
=
function
(
content
)
{
module
.
exports
=
function
(
content
)
{
if
(
this
.
resourceQuery
)
{
const
params
=
loaderUtils
.
parseQuery
(
this
.
resourceQuery
)
if
(
params
)
{
...
...
@@ -44,11 +48,18 @@ module.exports = function (content) {
this
.
cacheable
&&
this
.
cacheable
()
const
manifestJsonPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
manifest.json
'
)
const
pagesJsonJsPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
pagesJsonJsFileName
)
const
manifestJson
=
parseManifestJson
(
fs
.
readFileSync
(
manifestJsonPath
,
'
utf8
'
))
this
.
addDependency
(
manifestJsonPath
)
this
.
addDependency
(
pagesJsonJsPath
)
const
pagesJson
=
parsePagesJson
(
content
)
const
pagesJson
=
parsePagesJson
(
content
,
{
addDependency
:
(
file
)
=>
{
(
process
.
UNI_PAGES_DEPS
||
(
process
.
UNI_PAGES_DEPS
=
new
Set
())).
add
(
normalizePath
(
file
))
this
.
addDependency
(
file
)
}
})
if
(
manifestJson
.
transformPx
===
false
)
{
process
.
UNI_TRANSFORM_PX
=
false
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录