Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
b464a2f6
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
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,发现更多精彩内容 >>
提交
b464a2f6
编写于
11月 11, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): confusion
上级
260f39cb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
81 addition
and
51 deletion
+81
-51
packages/uni-app-vite/src/index.ts
packages/uni-app-vite/src/index.ts
+2
-2
packages/uni-app-vite/src/plugin/build.ts
packages/uni-app-vite/src/plugin/build.ts
+14
-3
packages/uni-app-vite/src/plugin/index.ts
packages/uni-app-vite/src/plugin/index.ts
+11
-14
packages/uni-app-vite/src/plugins/manifestJson.ts
packages/uni-app-vite/src/plugins/manifestJson.ts
+6
-11
packages/uni-cli-shared/src/json/app/manifest/confusion.ts
packages/uni-cli-shared/src/json/app/manifest/confusion.ts
+47
-20
packages/uni-cli-shared/src/json/app/manifest/index.ts
packages/uni-cli-shared/src/json/app/manifest/index.ts
+1
-1
未找到文件。
packages/uni-app-vite/src/index.ts
浏览文件 @
b464a2f6
...
...
@@ -9,7 +9,7 @@ import {
UNI_EASYCOM_EXCLUDE
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
plugins
as
nvuePlugins
}
from
'
@dcloudio/uni-cli-nvue
'
import
{
U
niAppPlugin
}
from
'
./plugin
'
import
{
u
niAppPlugin
}
from
'
./plugin
'
import
{
uniTemplatePlugin
}
from
'
./plugins/template
'
import
{
uniMainJsPlugin
}
from
'
./plugins/mainJs
'
import
{
uniManifestJsonPlugin
}
from
'
./plugins/manifestJson
'
...
...
@@ -53,7 +53,7 @@ const plugins = [
uniRenderjsPlugin
(),
uniTemplatePlugin
(),
uniStatsPlugin
(),
UniAppPlugin
,
uniAppPlugin
()
,
]
const
uniCssScopedPluginOptions
=
initUniCssScopedPluginOptions
()
...
...
packages/uni-app-vite/src/plugin/build.ts
浏览文件 @
b464a2f6
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
UserConfig
}
from
'
vite
'
import
{
ConfigEnv
,
UserConfig
}
from
'
vite
'
import
{
emptyDir
,
normalizePath
,
isConfusionFile
,
hasConfusionFile
,
resolveMainPathOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
export
function
buildOptions
():
UserConfig
[
'
build
'
]
{
export
function
buildOptions
(
configEnv
:
ConfigEnv
):
UserConfig
[
'
build
'
]
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
// 开始编译时,清空输出目录
...
...
@@ -41,7 +43,16 @@ export function buildOptions(): UserConfig['build'] {
}
return
'
uni-app:///
'
+
sourcePath
},
manualChunks
:
{},
manualChunks
(
id
)
{
if
(
hasConfusionFile
())
{
if
(
configEnv
.
mode
===
'
production
'
&&
isConfusionFile
(
path
.
relative
(
inputDir
,
id
))
)
{
return
'
app-confusion.js
'
}
}
},
chunkFileNames
(
chunk
)
{
if
(
chunk
.
isDynamicEntry
&&
chunk
.
facadeModuleId
)
{
const
filepath
=
path
.
relative
(
...
...
packages/uni-app-vite/src/plugin/index.ts
浏览文件 @
b464a2f6
...
...
@@ -4,18 +4,15 @@ import { uniOptions } from './uni'
import
{
buildOptions
}
from
'
./build
'
import
{
configResolved
}
from
'
./configResolved
'
export
const
UniAppPlugin
:
UniVitePlugin
=
{
name
:
'
vite:uni-app
'
,
uni
:
uniOptions
(),
config
()
{
return
{
build
:
buildOptions
(),
}
},
configResolved
,
// resolveId(id) {
// if (id === 'vue') {
// return resolveBuiltIn('@dcloudio/uni-app-vue')
// }
// },
export
function
uniAppPlugin
():
UniVitePlugin
{
return
{
name
:
'
vite:uni-app
'
,
uni
:
uniOptions
(),
config
(
_
,
env
)
{
return
{
build
:
buildOptions
(
env
),
}
},
configResolved
,
}
}
packages/uni-app-vite/src/plugins/manifestJson.ts
浏览文件 @
b464a2f6
...
...
@@ -11,6 +11,7 @@ import {
export
function
uniManifestJsonPlugin
():
Plugin
{
return
defineUniManifestJsonPlugin
((
opts
)
=>
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
return
{
name
:
'
vite:uni-app-manifest-json
'
,
enforce
:
'
pre
'
,
...
...
@@ -18,22 +19,16 @@ export function uniManifestJsonPlugin(): Plugin {
if
(
!
opts
.
filter
(
id
))
{
return
}
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
manifest.json
'
)
)
getLocaleFiles
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
locale
'
)
).
forEach
((
filepath
)
=>
{
this
.
addWatchFile
(
path
.
resolve
(
inputDir
,
'
manifest.json
'
))
getLocaleFiles
(
path
.
resolve
(
inputDir
,
'
locale
'
)).
forEach
((
filepath
)
=>
{
this
.
addWatchFile
(
filepath
)
})
const
manifestJson
=
normalizeAppManifestJson
(
parseJson
(
code
),
parsePagesJsonOnce
(
process
.
env
.
UNI_INPUT_DIR
,
process
.
env
.
UNI_PLATFORM
)
parsePagesJsonOnce
(
inputDir
,
process
.
env
.
UNI_PLATFORM
)
)
// 生成一个空的app-config.js,兼容基座已有规范
// 生成一个空的 app-config.js,兼容基座已有规范
this
.
emitFile
({
fileName
:
`app-config.js`
,
type
:
'
asset
'
,
...
...
packages/uni-cli-shared/src/json/app/manifest/confusion.ts
浏览文件 @
b464a2f6
import
path
from
'
path
'
import
{
normalizePath
}
from
'
../../../utils
'
import
{
EXTNAME_JS_RE
}
from
'
../../../constants
'
function
isJsFile
(
filename
:
string
)
{
return
EXTNAME_JS_RE
.
test
(
filename
)
}
function
isStaticJsFile
(
filename
:
string
)
{
return
(
filename
.
indexOf
(
'
hybrid/html
'
)
===
0
||
filename
.
indexOf
(
'
static/
'
)
===
0
||
filename
.
indexOf
(
'
/static/
'
)
!==
-
1
)
// subpackages, uni_modules 中的 static 目录
}
const
dynamicConfusionJsFiles
:
string
[]
=
[]
export
function
isConfusionFile
(
filename
:
string
)
{
return
dynamicConfusionJsFiles
.
includes
(
normalizePath
(
filename
))
}
export
function
hasConfusionFile
()
{
return
!!
dynamicConfusionJsFiles
.
length
}
export
function
initConfusion
(
manifestJson
:
Record
<
string
,
any
>
)
{
dynamicConfusionJsFiles
.
length
=
0
if
(
!
manifestJson
.
plus
.
confusion
?.
resources
)
{
return
}
...
...
@@ -7,26 +33,27 @@ export function initConfusion(manifestJson: Record<string, any>) {
string
,
string
>
manifestJson
.
plus
.
confusion
.
resources
=
Object
.
keys
(
resources
).
reduce
(
(
res
,
name
)
=>
{
const
extname
=
path
.
extname
(
name
)
if
(
extname
===
'
.nvue
'
)
{
res
[
name
.
replace
(
'
.nvue
'
,
'
.js
'
)]
=
resources
[
name
]
}
else
if
(
extname
===
'
.js
'
)
{
// 仅指定目录的js允许加密
if
(
name
.
indexOf
(
'
hybrid/html
'
)
===
0
||
name
.
indexOf
(
'
static/
'
)
===
0
||
name
.
indexOf
(
'
/static/
'
)
!==
-
1
// subpackages, uni_modules 中的 static 目录
)
{
res
[
name
]
=
resources
[
name
]
}
manifestJson
.
plus
.
confusion
.
resources
=
Object
.
keys
(
resources
).
reduce
<
Record
<
string
,
string
>
>
((
res
,
name
)
=>
{
const
extname
=
path
.
extname
(
name
)
if
(
extname
===
'
.nvue
'
)
{
res
[
name
.
replace
(
'
.nvue
'
,
'
.js
'
)]
=
resources
[
name
]
}
else
if
(
isJsFile
(
name
))
{
// 静态 js 加密
if
(
isStaticJsFile
(
name
))
{
res
[
name
]
=
resources
[
name
]
}
else
{
throw
new
Error
(
`原生混淆仅支持 nvue 页面,错误的页面路径:
${
name
}
`
)
// 非静态 js 将被合并进 app-confusion.js
dynamicConfusionJsFiles
.
push
(
name
)
}
// TODO 旧编译器会检查要加密的 nvue 页面(包括subnvue)是否被使用?后续有时间再考虑支持吧,意义不太大
return
res
},
{}
as
Record
<
string
,
string
>
)
}
else
{
throw
new
Error
(
`原生混淆仅支持 nvue 页面,错误的页面路径:
${
name
}
`
)
}
// TODO 旧编译器会检查要加密的 nvue 页面(包括subnvue)是否被使用?后续有时间再考虑支持吧,意义不太大
return
res
},
{})
if
(
dynamicConfusionJsFiles
.
length
)
{
manifestJson
.
plus
.
confusion
.
resources
[
'
app-confusion.js
'
]
=
{}
}
}
packages/uni-cli-shared/src/json/app/manifest/index.ts
浏览文件 @
b464a2f6
...
...
@@ -38,7 +38,7 @@ export function normalizeAppManifestJson(
}
export
*
from
'
./env
'
export
{
isConfusionFile
,
hasConfusionFile
}
from
'
./confusion
'
export
{
getNVueCompiler
,
getNVueStyleCompiler
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录