Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenYFan_OHHH
uni-app
提交
273e7f28
U
uni-app
项目概览
ChenYFan_OHHH
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
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,发现更多精彩内容 >>
提交
273e7f28
编写于
11月 18, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(cli): json cache
上级
b92c902c
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
80 addition
and
35 deletion
+80
-35
packages/uni-cli-shared/lib/cache.js
packages/uni-cli-shared/lib/cache.js
+57
-3
packages/vue-cli-plugin-hbuilderx/module-alias.js
packages/vue-cli-plugin-hbuilderx/module-alias.js
+12
-6
packages/vue-cli-plugin-uni/lib/env.js
packages/vue-cli-plugin-uni/lib/env.js
+9
-13
packages/vue-cli-plugin-uni/lib/h5/index.js
packages/vue-cli-plugin-uni/lib/h5/index.js
+1
-1
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
+1
-12
未找到文件。
packages/uni-cli-shared/lib/cache.js
浏览文件 @
273e7f28
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
crypto
=
require
(
'
crypto
'
)
/**
* 1.page-loader 缓存基础的 app.json page.json project.config.json
* 2.main-loader 缓存 app.json 中的 usingComponents 节点
...
...
@@ -228,6 +231,27 @@ function getSpecialMethods (name) {
return
componentSpecialMethods
[
name
]
||
[]
}
const
pagesJsonPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
pages.json
'
)
const
cacheTypes
=
[
'
babel-loader
'
,
'
css-loader
'
,
'
uni-template-compiler
'
,
'
vue-loader
'
]
function
clearCache
()
{
const
fsExtra
=
require
(
'
fs-extra
'
)
cacheTypes
.
forEach
(
cacheType
=>
{
fsExtra
.
emptyDirSync
(
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
node_modules/.cache/
'
+
cacheType
+
'
/
'
+
process
.
env
.
UNI_PLATFORM
))
})
}
function
digest
(
str
)
{
return
crypto
.
createHash
(
'
md5
'
)
.
update
(
str
)
.
digest
(
'
hex
'
)
}
module
.
exports
=
{
getPageSet
()
{
return
pageSet
...
...
@@ -235,21 +259,50 @@ module.exports = {
getJsonFileMap
()
{
return
jsonFileMap
},
// 先简单处理,该方案不好,
// 后续为 pages-loader 增加 cache-loader,
// 然后其他修改 json 的地方也要定制 cache-loader
store
()
{
const
filepath
=
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
node_modules/.cache/uni-pages-loader/
'
+
process
.
env
.
UNI_PLATFORM
,
digest
(
process
.
env
.
UNI_INPUT_DIR
)
+
'
.json
'
)
const
files
=
Array
.
from
(
jsonFileMap
.
entries
())
const
pages
=
Array
.
from
(
pageSet
)
const
components
=
Array
.
from
(
componentSet
)
const
methods
=
componentSpecialMethods
return
JSON
.
stringify
({
fs
.
writeFileSync
(
filepath
,
JSON
.
stringify
({
mtimeMs
:
fs
.
statSync
(
pagesJsonPath
).
mtimeMs
,
files
,
pages
,
components
,
methods
,
globalUsingComponents
,
appJsonUsingComponents
})
})
)
},
restore
(
jsonCache
)
{
restore
()
{
const
filepath
=
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
node_modules/.cache/uni-pages-loader/
'
+
process
.
env
.
UNI_PLATFORM
,
digest
(
process
.
env
.
UNI_INPUT_DIR
)
+
'
.json
'
)
if
(
!
fs
.
existsSync
(
filepath
))
{
try
{
clearCache
()
}
catch
(
e
)
{}
return
}
const
mtimeMs
=
fs
.
statSync
(
pagesJsonPath
).
mtimeMs
const
jsonCache
=
require
(
filepath
)
if
(
jsonCache
.
mtimeMs
!==
mtimeMs
)
{
try
{
clearCache
()
}
catch
(
e
)
{}
return
}
jsonFileMap
=
new
Map
(
jsonCache
.
files
)
pageSet
=
new
Set
(
jsonCache
.
pages
)
componentSet
=
new
Set
(
jsonCache
.
components
)
...
...
@@ -260,6 +313,7 @@ module.exports = {
for
(
let
name
of
jsonFileMap
.
keys
())
{
changedJsonFileSet
.
add
(
name
)
}
return
true
},
getJsonFile
,
getPagesJson
,
...
...
packages/vue-cli-plugin-hbuilderx/module-alias.js
浏览文件 @
273e7f28
...
...
@@ -20,12 +20,18 @@ moduleAlias.addAlias('./templateLoader', (fromPath, request, alias) => {
return
request
})
// vue cache
moduleAlias
.
addAlias
(
'
./loaders/pitcher
'
,
(
fromPath
,
request
,
alias
)
=>
{
if
(
// 非 h5 ,非 v3,非 native
process
.
env
.
UNI_PLATFORM
!==
'
h5
'
&&
!
process
.
env
.
UNI_USING_V3
&&
!
process
.
env
.
UNI_USING_NATIVE
)
{
moduleAlias
.
addAlias
(
'
./loaders/pitcher
'
,
(
fromPath
,
request
,
alias
)
=>
{
if
(
fromPath
.
indexOf
(
'
vue-loader
'
)
!==
-
1
)
{
return
path
.
resolve
(
__dirname
,
'
packages/vue-loader/lib/loaders/pitcher
'
)
}
return
request
})
})
}
if
(
isInHBuilderX
)
{
moduleAlias
.
addAlias
(
'
typescript
'
,
path
.
resolve
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
,
...
...
packages/vue-cli-plugin-uni/lib/env.js
浏览文件 @
273e7f28
...
...
@@ -262,24 +262,20 @@ if (runByHBuilderX) {
}
}
if
(
process
.
env
.
UNI_USING_CACHE
)
{
// 使用 cache, 拷贝 cache 的 json
const
cacheJsonPath
=
path
.
resolve
(
if
(
process
.
env
.
UNI_USING_CACHE
&&
process
.
env
.
UNI_PLATFORM
!==
'
h5
'
&&
!
process
.
env
.
UNI_USING_V3
&&
!
process
.
env
.
UNI_USING_NATIVE
)
{
// 使用 cache, 拷贝 cache 的 json
const
cacheJsonDir
=
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
node_modules/.cache/uni-pages-loader/
'
+
process
.
env
.
UNI_PLATFORM
,
'
cache.json
'
'
node_modules/.cache/uni-pages-loader/
'
+
process
.
env
.
UNI_PLATFORM
)
const
cacheJsonDir
=
path
.
dirname
(
cacheJsonPath
)
if
(
!
fs
.
existsSync
(
cacheJsonDir
))
{
// 创建 cache 目录
mkdirp
(
cacheJsonDir
)
}
else
{
if
(
fs
.
existsSync
(
cacheJsonPath
))
{
// 设置 json 缓存
const
{
restore
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/cache
'
)
restore
(
require
(
cacheJsonPath
))
}
require
(
'
@dcloudio/uni-cli-shared/lib/cache
'
).
restore
()
}
}
...
...
packages/vue-cli-plugin-uni/lib/h5/index.js
浏览文件 @
273e7f28
...
...
@@ -7,7 +7,7 @@ const {
getPlatformCssnano
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
modifyVueLoader
=
require
(
'
./vue-loader
'
)
const
modifyVueLoader
=
require
(
'
.
.
/vue-loader
'
)
const
WebpackHtmlAppendPlugin
=
require
(
'
../../packages/webpack-html-append-plugin
'
)
...
...
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
浏览文件 @
273e7f28
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
{
...
...
@@ -177,17 +176,7 @@ module.exports = function generateJson (compilation) {
}
if
(
process
.
env
.
UNI_USING_CACHE
&&
jsonFileMap
.
size
)
{
setTimeout
(()
=>
{
const
{
store
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/cache
'
)
const
filepath
=
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
node_modules/.cache/uni-pages-loader/
'
+
process
.
env
.
UNI_PLATFORM
,
'
cache.json
'
)
// 异步写入 cache,避免影响热更新性能
fs
.
writeFileSync
(
filepath
,
store
())
require
(
'
@dcloudio/uni-cli-shared/lib/cache
'
).
store
()
},
50
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录