Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
m0_68066342
uni-app
提交
b92c902c
U
uni-app
项目概览
m0_68066342
/
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,发现更多精彩内容 >>
提交
b92c902c
编写于
11月 18, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(cli): add json cache
上级
6de497bc
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
76 addition
and
7 deletion
+76
-7
packages/uni-cli-shared/lib/cache.js
packages/uni-cli-shared/lib/cache.js
+29
-3
packages/vue-cli-plugin-uni/lib/cache-loader.js
packages/vue-cli-plugin-uni/lib/cache-loader.js
+0
-1
packages/vue-cli-plugin-uni/lib/env.js
packages/vue-cli-plugin-uni/lib/env.js
+25
-0
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
+22
-3
未找到文件。
packages/uni-cli-shared/lib/cache.js
浏览文件 @
b92c902c
...
@@ -4,11 +4,11 @@
...
@@ -4,11 +4,11 @@
* 3.script-loader 修改缓存 usingComponents 节点
* 3.script-loader 修改缓存 usingComponents 节点
* 5.webpack plugin 中获取被修改的 page.json,component.json 并 emitFile
* 5.webpack plugin 中获取被修改的 page.json,component.json 并 emitFile
*/
*/
cons
t
jsonFileMap
=
new
Map
()
le
t
jsonFileMap
=
new
Map
()
const
changedJsonFileSet
=
new
Set
()
const
changedJsonFileSet
=
new
Set
()
cons
t
componentSet
=
new
Set
()
le
t
componentSet
=
new
Set
()
cons
t
pageSet
=
new
Set
()
le
t
pageSet
=
new
Set
()
let
globalUsingComponents
=
Object
.
create
(
null
)
let
globalUsingComponents
=
Object
.
create
(
null
)
let
appJsonUsingComponents
=
Object
.
create
(
null
)
let
appJsonUsingComponents
=
Object
.
create
(
null
)
...
@@ -235,6 +235,32 @@ module.exports = {
...
@@ -235,6 +235,32 @@ module.exports = {
getJsonFileMap
()
{
getJsonFileMap
()
{
return
jsonFileMap
return
jsonFileMap
},
},
store
()
{
const
files
=
Array
.
from
(
jsonFileMap
.
entries
())
const
pages
=
Array
.
from
(
pageSet
)
const
components
=
Array
.
from
(
componentSet
)
const
methods
=
componentSpecialMethods
return
JSON
.
stringify
({
files
,
pages
,
components
,
methods
,
globalUsingComponents
,
appJsonUsingComponents
})
},
restore
(
jsonCache
)
{
jsonFileMap
=
new
Map
(
jsonCache
.
files
)
pageSet
=
new
Set
(
jsonCache
.
pages
)
componentSet
=
new
Set
(
jsonCache
.
components
)
componentSpecialMethods
=
jsonCache
.
methods
globalUsingComponents
=
jsonCache
.
globalUsingComponents
appJsonUsingComponents
=
jsonCache
.
appJsonUsingComponents
// restore 时,所有 file 均触发 change
for
(
let
name
of
jsonFileMap
.
keys
())
{
changedJsonFileSet
.
add
(
name
)
}
},
getJsonFile
,
getJsonFile
,
getPagesJson
,
getPagesJson
,
getComponentSet
,
getComponentSet
,
...
...
packages/vue-cli-plugin-uni/lib/cache-loader.js
浏览文件 @
b92c902c
...
@@ -51,7 +51,6 @@ function read (key, callback) {
...
@@ -51,7 +51,6 @@ function read (key, callback) {
const
mpTemplates
=
data
[
'
mpTemplates
'
]
const
mpTemplates
=
data
[
'
mpTemplates
'
]
if
(
mpTemplates
)
{
if
(
mpTemplates
)
{
Object
.
keys
(
mpTemplates
).
forEach
(
name
=>
{
Object
.
keys
(
mpTemplates
).
forEach
(
name
=>
{
console
.
log
(
'
read=>write
'
,
name
)
fs
.
writeFileSync
(
name
,
mpTemplates
[
name
],
'
utf-8
'
)
fs
.
writeFileSync
(
name
,
mpTemplates
[
name
],
'
utf-8
'
)
})
})
}
}
...
...
packages/vue-cli-plugin-uni/lib/env.js
浏览文件 @
b92c902c
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
path
=
require
(
'
path
'
)
const
mkdirp
=
require
(
'
mkdirp
'
)
// 初始化环境变量
// 初始化环境变量
const
defaultInputDir
=
'
../../../../src
'
const
defaultInputDir
=
'
../../../../src
'
...
@@ -119,6 +121,8 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
...
@@ -119,6 +121,8 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
isNVueCompiler
=
false
isNVueCompiler
=
false
}
}
if
(
platformOptions
.
renderer
===
'
native
'
)
{
if
(
platformOptions
.
renderer
===
'
native
'
)
{
// 纯原生目前不提供 cache
process
.
env
.
UNI_USING_CACHE
=
false
process
.
env
.
UNI_USING_NATIVE
=
true
process
.
env
.
UNI_USING_NATIVE
=
true
process
.
env
.
UNI_USING_V8
=
true
process
.
env
.
UNI_USING_V8
=
true
process
.
env
.
UNI_OUTPUT_TMP_DIR
=
''
process
.
env
.
UNI_OUTPUT_TMP_DIR
=
''
...
@@ -258,6 +262,27 @@ if (runByHBuilderX) {
...
@@ -258,6 +262,27 @@ if (runByHBuilderX) {
}
}
}
}
if
(
process
.
env
.
UNI_USING_CACHE
)
{
// 使用 cache, 拷贝 cache 的 json
const
cacheJsonPath
=
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
node_modules/.cache/uni-pages-loader/
'
+
process
.
env
.
UNI_PLATFORM
,
'
cache.json
'
)
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
))
}
}
}
runByHBuilderX
&&
console
.
log
(
`正在编译中...`
)
runByHBuilderX
&&
console
.
log
(
`正在编译中...`
)
module
.
exports
=
{
module
.
exports
=
{
...
...
packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
浏览文件 @
b92c902c
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
path
=
require
(
'
path
'
)
const
{
const
{
...
@@ -153,7 +154,7 @@ module.exports = function generateJson (compilation) {
...
@@ -153,7 +154,7 @@ module.exports = function generateJson (compilation) {
!
[
'
app.js
'
,
'
manifest.js
'
,
'
project.config.js
'
,
'
project.swan.js
'
].
includes
(
jsFile
)
&&
!
[
'
app.js
'
,
'
manifest.js
'
,
'
project.config.js
'
,
'
project.swan.js
'
].
includes
(
jsFile
)
&&
!
compilation
.
assets
[
jsFile
]
!
compilation
.
assets
[
jsFile
]
)
{
)
{
co
mpilation
.
assets
[
jsFile
]
=
{
co
nst
jsFileAsset
=
{
size
()
{
size
()
{
return
Buffer
.
byteLength
(
EMPTY_COMPONENT
,
'
utf8
'
)
return
Buffer
.
byteLength
(
EMPTY_COMPONENT
,
'
utf8
'
)
},
},
...
@@ -161,8 +162,9 @@ module.exports = function generateJson (compilation) {
...
@@ -161,8 +162,9 @@ module.exports = function generateJson (compilation) {
return
EMPTY_COMPONENT
return
EMPTY_COMPONENT
}
}
}
}
compilation
.
assets
[
jsFile
]
=
jsFileAsset
}
}
co
mpilation
.
assets
[
name
]
=
{
co
nst
jsonAsset
=
{
size
()
{
size
()
{
return
Buffer
.
byteLength
(
source
,
'
utf8
'
)
return
Buffer
.
byteLength
(
source
,
'
utf8
'
)
},
},
...
@@ -170,5 +172,22 @@ module.exports = function generateJson (compilation) {
...
@@ -170,5 +172,22 @@ module.exports = function generateJson (compilation) {
return
source
return
source
}
}
}
}
compilation
.
assets
[
name
]
=
jsonAsset
}
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
())
},
50
)
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录