Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
9e9456bb
U
uni-app
项目概览
DCloud
/
uni-app
大约 1 个月 前同步成功
通知
702
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9e9456bb
编写于
1月 09, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
build(deps): bump vite from 1.0.0-rc.13 to 2.0.0-beta.4
上级
3001efa9
变更
20
展开全部
隐藏空白更改
内联
并排
Showing
20 changed file
with
584 addition
and
1240 deletion
+584
-1240
.eslintrc.js
.eslintrc.js
+15
-15
package.json
package.json
+30
-30
packages/uni-components/vite.config.ts
packages/uni-components/vite.config.ts
+33
-25
packages/uni-h5/vite.config.ts
packages/uni-h5/vite.config.ts
+56
-34
packages/uni-mp-vue/lib/vue.runtime.esm.js
packages/uni-mp-vue/lib/vue.runtime.esm.js
+1
-1
packages/vite-plugin-uni/package.json
packages/vite-plugin-uni/package.json
+2
-1
packages/vite-plugin-uni/src/index.ts
packages/vite-plugin-uni/src/index.ts
+37
-31
packages/vite-plugin-uni/src/server/index.ts
packages/vite-plugin-uni/src/server/index.ts
+3
-3
packages/vite-plugin-uni/src/server/serveEasycom.ts
packages/vite-plugin-uni/src/server/serveEasycom.ts
+15
-0
packages/vite-plugin-uni/src/server/serveMainJs.ts
packages/vite-plugin-uni/src/server/serveMainJs.ts
+3
-3
packages/vite-plugin-uni/src/server/servePagesJson.ts
packages/vite-plugin-uni/src/server/servePagesJson.ts
+3
-3
packages/vite-plugin-uni/src/server/serverPluginEnv.ts
packages/vite-plugin-uni/src/server/serverPluginEnv.ts
+0
-15
packages/vite-plugin-uni/src/utils/dynamicImport.ts
packages/vite-plugin-uni/src/utils/dynamicImport.ts
+0
-0
packages/vite-plugin-uni/src/utils/easycom.ts
packages/vite-plugin-uni/src/utils/easycom.ts
+2
-2
packages/vite-plugin-uni/src/utils/index.ts
packages/vite-plugin-uni/src/utils/index.ts
+5
-3
packages/vite-plugin-uni/src/utils/mainJs.ts
packages/vite-plugin-uni/src/utils/mainJs.ts
+1
-1
packages/vite-plugin-uni/src/utils/pagesJson.ts
packages/vite-plugin-uni/src/utils/pagesJson.ts
+8
-8
packages/vite-plugin-uni/src/utils/transform.ts
packages/vite-plugin-uni/src/utils/transform.ts
+18
-0
scripts/build.js
scripts/build.js
+13
-9
yarn.lock
yarn.lock
+339
-1056
未找到文件。
.eslintrc.js
浏览文件 @
9e9456bb
...
...
@@ -4,14 +4,14 @@ const NodeGlobals = ['module', 'require']
module
.
exports
=
{
parser
:
'
@typescript-eslint/parser
'
,
parserOptions
:
{
sourceType
:
'
module
'
sourceType
:
'
module
'
,
},
rules
:
{
'
no-unused-vars
'
:
[
'
error
'
,
// we are only using this rule to check for unused arguments since TS
// catches unused variables but not args.
{
varsIgnorePattern
:
'
.*
'
,
args
:
'
after-used
'
,
argsIgnorePattern
:
'
^_
'
}
{
varsIgnorePattern
:
'
.*
'
,
args
:
'
after-used
'
,
argsIgnorePattern
:
'
^_
'
}
,
],
// most of the codebase are expected to be env agnostic
'
no-restricted-globals
'
:
[
'
error
'
,
...
DOMGlobals
,
...
NodeGlobals
],
...
...
@@ -20,8 +20,8 @@ module.exports = {
'
no-restricted-syntax
'
:
[
'
error
'
,
'
ObjectExpression > SpreadElement
'
,
'
ObjectPattern > RestElement
'
]
'
ObjectPattern > RestElement
'
,
]
,
},
overrides
:
[
// tests, no restrictions (runs in Node / jest with jsdom)
...
...
@@ -29,28 +29,28 @@ module.exports = {
files
:
[
'
**/__tests__/**
'
],
rules
:
{
'
no-restricted-globals
'
:
'
off
'
,
'
no-restricted-syntax
'
:
'
off
'
}
'
no-restricted-syntax
'
:
'
off
'
,
}
,
},
// Packages targeting DOM
{
files
:
[
'
packages/{uni-components,uni-h5,uni-h5-vue,uni-shared,uni-core}/**
'
'
packages/{uni-components,uni-h5,uni-h5-vue,uni-shared,uni-core}/**
'
,
],
rules
:
{
'
no-restricted-globals
'
:
[
'
error
'
,
...
NodeGlobals
]
}
'
no-restricted-globals
'
:
[
'
error
'
,
...
NodeGlobals
]
,
}
,
},
// Packages targeting Node
{
files
:
[
'
packages/{vue-cli-plugin-uni,vue-cli-plugin-hbuilderx}/**
'
,
'
packages/*/vite.config.ts
'
'
packages/{vue-cli-plugin-uni,vue-cli-plugin-hbuilderx
,vite-plugin-uni
}/**
'
,
'
packages/*/vite.config.ts
'
,
],
rules
:
{
'
no-restricted-globals
'
:
[
'
error
'
,
...
DOMGlobals
],
'
no-restricted-syntax
'
:
'
off
'
}
}
]
'
no-restricted-syntax
'
:
'
off
'
,
}
,
}
,
]
,
}
package.json
浏览文件 @
9e9456bb
...
...
@@ -5,7 +5,6 @@
"packages/*"
],
"scripts"
:
{
"dev"
:
"node scripts/dev.js"
,
"build"
:
"node scripts/build.js"
,
"lint"
:
"eslint packages/**/*.ts"
,
"format"
:
"prettier --write --parser typescript
\"
packages/**/*.ts?(x)
\"
"
,
...
...
@@ -34,41 +33,42 @@
"node"
:
">=10.0.0"
},
"devDependencies"
:
{
"
@dcloudio/types
"
:
"
^2.0.0
"
,
"
@ls-lint/ls-lint
"
:
"
^1.
8.0
"
,
"
@microsoft/api-extractor
"
:
"
^7.
3.9
"
,
"
@dcloudio/types
"
:
"
^2.0.
2
0
"
,
"
@ls-lint/ls-lint
"
:
"
^1.
9.2
"
,
"
@microsoft/api-extractor
"
:
"
^7.
12.1
"
,
"
@rollup/plugin-alias
"
:
"
^3.1.1
"
,
"
@rollup/plugin-commonjs
"
:
"
^1
5
.0.0
"
,
"
@rollup/plugin-json
"
:
"
^4.
0
.0
"
,
"
@rollup/plugin-node-resolve
"
:
"
^
8.0.0
"
,
"
@rollup/plugin-replace
"
:
"
^2.
2.1
"
,
"
@rollup/plugin-commonjs
"
:
"
^1
7
.0.0
"
,
"
@rollup/plugin-json
"
:
"
^4.
1
.0
"
,
"
@rollup/plugin-node-resolve
"
:
"
^
11.0.1
"
,
"
@rollup/plugin-replace
"
:
"
^2.
3.4
"
,
"
@types/debug
"
:
"
^4.1.5
"
,
"
@types/fs-extra
"
:
"
^9.0.5
"
,
"
@types/jest
"
:
"
^26.0.0
"
,
"
@types/node
"
:
"
13.11.1
"
,
"
@types/puppeteer
"
:
"
^2.0.0
"
,
"
@typescript-eslint/parser
"
:
"
^3.2.0
"
,
"
@vue/compiler-sfc
"
:
"
^3.0.0-rc.9
"
,
"
@types/fs-extra
"
:
"
^9.0.6
"
,
"
@types/jest
"
:
"
^26.0.19
"
,
"
@types/node
"
:
"
^14.14.20
"
,
"
@types/puppeteer
"
:
"
^5.4.2
"
,
"
@typescript-eslint/parser
"
:
"
^4.12.0
"
,
"
@vitejs/plugin-vue
"
:
"
^1.0.4
"
,
"
@vue/compiler-sfc
"
:
"
^3.0.5
"
,
"
brotli
"
:
"
^1.3.2
"
,
"
eslint
"
:
"
^7.
2
.0
"
,
"
eslint
"
:
"
^7.
17
.0
"
,
"
fs-extra
"
:
"
^9.0.1
"
,
"
jest
"
:
"
^26.
0.1
"
,
"
lint-staged
"
:
"
^10.
2.10
"
,
"
mini-types
"
:
"
^0.1.
3
"
,
"
miniprogram-api-typings
"
:
"
^
2.11.0-1
"
,
"
prettier
"
:
"
~1.14.0
"
,
"
puppeteer
"
:
"
^
2.0
.0
"
,
"
rollup
"
:
"
^2.
16
.1
"
,
"
jest
"
:
"
^26.
6.3
"
,
"
lint-staged
"
:
"
^10.
5.3
"
,
"
mini-types
"
:
"
^0.1.
4
"
,
"
miniprogram-api-typings
"
:
"
^
3.2.0
"
,
"
prettier
"
:
"
^2.2.1
"
,
"
puppeteer
"
:
"
^
5.5
.0
"
,
"
rollup
"
:
"
^2.
35
.1
"
,
"
rollup-plugin-node-builtins
"
:
"
^2.1.2
"
,
"
rollup-plugin-node-globals
"
:
"
^1.4.0
"
,
"
rollup-plugin-terser
"
:
"
^
6.1.0
"
,
"
rollup-plugin-typescript2
"
:
"
^0.2
7.1
"
,
"
rollup-plugin-vue
"
:
"
^6.0.0
-beta.10
"
,
"
semver
"
:
"
^7.3.
2
"
,
"
ts-jest
"
:
"
^26.
1.0
"
,
"
typescript
"
:
"
^
3.9
.3
"
,
"
vite
"
:
"
^
1.0.0-rc.13
"
,
"
vue
"
:
"
^3.0.3
"
,
"
rollup-plugin-terser
"
:
"
^
7.0.2
"
,
"
rollup-plugin-typescript2
"
:
"
^0.2
9.0
"
,
"
rollup-plugin-vue
"
:
"
^6.0.0
"
,
"
semver
"
:
"
^7.3.
4
"
,
"
ts-jest
"
:
"
^26.
4.4
"
,
"
typescript
"
:
"
^
4.1
.3
"
,
"
vite
"
:
"
^
2.0.0-beta.4
"
,
"
vue
"
:
"
3.0.5
"
,
"
yorkie
"
:
"
^2.0.0
"
}
}
packages/uni-components/vite.config.ts
浏览文件 @
9e9456bb
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
defineConfig
}
from
'
vite
'
import
vue
from
'
@vitejs/plugin-vue
'
import
{
isCustomElement
}
from
'
../uni-shared
'
export
default
{
export
default
defineConfig
(
{
root
:
'
.
'
,
minify
:
false
,
assetsDir
:
'
.
'
,
emitAssets
:
false
,
define
:
{
__PLATFORM__
:
JSON
.
stringify
(
'
app-plus
'
)
__PLATFORM__
:
JSON
.
stringify
(
'
app-plus
'
)
,
},
vueCompilerOptions
:
{
isCustomElement
plugins
:
[
vue
({
template
:
{
compilerOptions
:
{
isCustomElement
,
},
},
}),
],
build
:
{
minify
:
false
,
assetsDir
:
'
.
'
,
rollupOptions
:
{
input
:
'
src/index.ts
'
,
external
:
[
'
vue
'
,
'
@vue/shared
'
,
'
@dcloudio/uni-shared
'
],
preserveEntrySignatures
:
'
strict
'
,
output
:
{
format
:
'
es
'
,
entryFileNames
:
'
uni-components.esm.js
'
,
assetFileNames
(
assetInfo
)
{
if
(
assetInfo
.
name
===
'
style.css
'
)
{
return
'
uni-components.css
'
}
return
'
assets/[name]-[hash][extname]
'
},
},
},
// emitAssets: false,
},
rollupInputOptions
:
{
input
:
'
src/index.ts
'
,
external
:
[
'
vue
'
,
'
@vue/shared
'
,
'
@dcloudio/uni-shared
'
],
preserveEntrySignatures
:
'
strict
'
},
rollupOutputOptions
:
{
format
:
'
es
'
,
entryFileNames
:
'
uni-components.esm.js
'
,
assetFileNames
(
assetInfo
)
{
if
(
assetInfo
.
name
===
'
style.css
'
)
{
return
'
uni-components.css
'
}
return
'
assets/[name]-[hash][extname]
'
}
}
}
})
packages/uni-h5/vite.config.ts
浏览文件 @
9e9456bb
import
path
from
'
path
'
import
{
defineConfig
}
from
'
vite
'
import
vue
from
'
@vitejs/plugin-vue
'
import
replace
from
'
@rollup/plugin-replace
'
import
{
isCustomElement
}
from
'
../uni-shared
'
...
...
@@ -8,43 +11,62 @@ function resolve(file: string) {
return
path
.
resolve
(
__dirname
,
file
)
}
export
default
{
export
default
defineConfig
(
{
root
:
'
.
'
,
minify
:
false
,
assetsDir
:
'
.
'
,
emitAssets
:
false
,
alias
:
{
'
@dcloudio/uni-api
'
:
resolve
(
'
../uni-api/src/index.ts
'
),
'
@dcloudio/uni-vue
'
:
resolve
(
'
../uni-vue/src/index.ts
'
),
'
@dcloudio/uni-core
'
:
resolve
(
'
../uni-core/src/index.ts
'
),
'
@dcloudio/uni-components
'
:
resolve
(
'
../uni-components/src/index.ts
'
)
},
define
:
{
global
:
'
window
'
,
__DEV__
:
`(process.env.NODE_ENV !== 'production')`
,
__PLATFORM__
:
JSON
.
stringify
(
'
h5
'
)
__PLATFORM__
:
JSON
.
stringify
(
'
h5
'
)
,
},
vueCompilerOptions
:
{
isCustomElement
alias
:
[
{
find
:
'
@dcloudio/uni-api
'
,
replacement
:
resolve
(
'
../uni-api/src/index.ts
'
),
},
{
find
:
'
@dcloudio/uni-vue
'
,
replacement
:
resolve
(
'
../uni-vue/src/index.ts
'
),
},
{
find
:
'
@dcloudio/uni-core
'
,
replacement
:
resolve
(
'
../uni-core/src/index.ts
'
),
},
{
find
:
'
@dcloudio/uni-components
'
,
replacement
:
resolve
(
'
../uni-components/src/index.ts
'
),
},
],
plugins
:
[
vue
({
template
:
{
compilerOptions
:
{
isCustomElement
,
},
},
}),
],
build
:
{
minify
:
false
,
assetsDir
:
'
.
'
,
rollupOptions
:
{
input
:
'
src/index.ts
'
,
external
:
[
'
vue
'
,
'
vue-router
'
,
'
@vue/shared
'
,
'
@dcloudio/uni-shared
'
],
preserveEntrySignatures
:
'
strict
'
,
plugins
:
[
replace
({
createApi
:
`/*#__PURE__*/ createApi`
,
}),
],
output
:
{
format
:
'
es
'
,
entryFileNames
:
'
uni-h5.esm.js
'
,
assetFileNames
(
assetInfo
)
{
if
(
assetInfo
.
name
===
'
style.css
'
)
{
return
'
uni-h5.css
'
}
return
'
assets/[name]-[hash][extname]
'
},
},
},
},
rollupInputOptions
:
{
input
:
'
src/index.ts
'
,
external
:
[
'
vue
'
,
'
vue-router
'
,
'
@vue/shared
'
,
'
@dcloudio/uni-shared
'
],
preserveEntrySignatures
:
'
strict
'
,
plugins
:
[
replace
({
createApi
:
`/*#__PURE__*/ createApi`
})
]
},
rollupOutputOptions
:
{
format
:
'
es
'
,
entryFileNames
:
'
uni-h5.esm.js
'
,
assetFileNames
(
assetInfo
)
{
if
(
assetInfo
.
name
===
'
style.css
'
)
{
return
'
uni-h5.css
'
}
return
'
assets/[name]-[hash][extname]
'
}
}
}
})
packages/uni-mp-vue/lib/vue.runtime.esm.js
浏览文件 @
9e9456bb
...
...
@@ -3247,7 +3247,7 @@ function defineEmit() {
}
// Core API ------------------------------------------------------------------
const
version
=
"
3.0.
4
"
;
const
version
=
"
3.0.
5
"
;
// import deepCopy from './deepCopy'
/**
...
...
packages/vite-plugin-uni/package.json
浏览文件 @
9e9456bb
...
...
@@ -22,12 +22,13 @@
"license"
:
"Apache-2.0"
,
"dependencies"
:
{
"@rollup/pluginutils"
:
"^4.1.0"
,
"debug"
:
"^4.3.1"
,
"estree-walker"
:
"^2.0.1"
,
"fs-extra"
:
"^9.0.1"
,
"magic-string"
:
"^0.25.7"
},
"peerDependencies"
:
{
"@dcloudio/uni-cli-shared"
:
"^3.0.0"
,
"vite"
:
"^
1.0.0-rc.13
"
"vite"
:
"^
2.0.0-beta.4
"
}
}
packages/vite-plugin-uni/src/index.ts
浏览文件 @
9e9456bb
...
...
@@ -5,7 +5,7 @@ import { vueCompilerOptions } from '@dcloudio/uni-cli-shared'
import
{
serverPluginEnv
,
serverPluginMainJs
,
serverPluginPagesJson
serverPluginPagesJson
,
}
from
'
./server
'
import
{
...
...
@@ -13,19 +13,18 @@ import {
buildPluginInject
,
buildPluginMainJs
,
buildPluginPagesJson
,
buildPluginDynamicImport
buildPluginDynamicImport
,
}
from
'
./build
'
import
{
dynamicImportCode
}
from
'
./utils/dynamicImportUtils
'
import
{
initEasycoms
}
from
'
./utils/easycomUtils
'
import
{
initEasycoms
,
dynamicImportCode
,
transform
}
from
'
./utils
'
const
VUES
=
[
'
vue
'
,
'
vue.js
'
,
'
./vue.js
'
]
const
VUES
=
[
'
vue
'
,
'
vue.js
'
,
'
./vue.js
'
,
'
dist/vue.runtime.esm-bundler.js
'
]
const
plugins
=
[
buildPluginMainJs
,
buildPluginPagesJson
,
buildPluginInject
,
buildPluginCopy
buildPluginCopy
,
]
if
(
dynamicImportCode
)
{
...
...
@@ -33,49 +32,56 @@ if (dynamicImportCode) {
}
const
plugin
:
Plugin
=
{
define
:
{
__UNI_WX_API__
:
true
,
__UNI_WXS_API__
:
true
,
__UNI_ROUTER_MODE__
:
JSON
.
stringify
(
'
hash
'
)
},
resolvers
:
[
{
alias
(
id
:
string
)
{
if
(
VUES
.
includes
(
id
))
{
return
'
@dcloudio/uni-h5-vue
'
}
if
(
id
.
startsWith
(
'
@/
'
))
{
return
id
.
replace
(
'
@/
'
,
'
/src/
'
)
}
}
}
],
configureServer
:
[
serverPluginEnv
,
serverPluginMainJs
,
serverPluginPagesJson
],
rollupInputOptions
:
{
plugins
plugins
,
},
vueCompilerOptions
,
configureBuild
({
root
})
{
initEasycoms
(
root
)
}
}
,
}
// TODO 等待 vite 升级支持以下配置
Object
.
assign
(
plugin
,
{
optimizeDeps
:
{
exclude
:
[
'
vue
'
,
'
vue-router
'
,
'
@dcloudio/uni-h5
'
,
'
@dcloudio/uni-h5-vue
'
,
'
@dcloudio/uni-shared
'
]
'
@dcloudio/uni-shared
'
,
]
,
},
chokidarWatchOptions
:
{
ignored
:
[
'
**/node_modules/**
'
,
'
**/.git/**
'
,
'
**/uniCloud-aliyun/**
'
,
'
**/uniCloud-tcb/**
'
]
}
'
**/uniCloud-tcb/**
'
,
]
,
}
,
})
export
default
plugin
interface
Options
{}
export
default
function
uniPlugin
(
_rawOptions
:
Options
=
{}):
Plugin
{
return
{
name
:
'
vite:uni
'
,
config
(
config
)
{
config
.
define
=
{
__UNI_WX_API__
:
true
,
__UNI_WXS_API__
:
true
,
__UNI_ROUTER_MODE__
:
JSON
.
stringify
(
'
hash
'
),
...
config
.
define
,
}
},
async
resolveId
(
id
)
{
if
(
VUES
.
includes
(
id
))
{
return
'
@dcloudio/uni-h5-vue
'
}
if
(
id
.
startsWith
(
'
@/
'
))
{
return
id
.
replace
(
'
@/
'
,
'
/src/
'
)
}
},
transform
,
configureServer
()
{},
}
}
packages/vite-plugin-uni/src/server/index.ts
浏览文件 @
9e9456bb
export
*
from
'
./serve
rPluginEnv
'
export
*
from
'
./serve
rPlugin
MainJs
'
export
*
from
'
./serve
rPlugin
PagesJson
'
export
*
from
'
./serve
Easycom
'
export
*
from
'
./serveMainJs
'
export
*
from
'
./servePagesJson
'
packages/vite-plugin-uni/src/server/serveEasycom.ts
0 → 100644
浏览文件 @
9e9456bb
import
{
ViteDevServer
}
from
'
vite
'
import
{
initEasycoms
}
from
'
../utils
'
export
const
serveEasycom
=
(
server
:
ViteDevServer
)
=>
{
const
{
dirs
,
refresh
}
=
initEasycoms
(
server
.
config
.
root
)
server
.
watcher
.
on
(
'
all
'
,
(
eventName
,
path
)
=>
{
if
(
!
[
'
add
'
,
'
unlink
'
].
includes
(
eventName
))
{
return
}
if
(
dirs
.
find
((
dir
)
=>
path
.
startsWith
(
dir
)))
{
refresh
()
}
})
}
packages/vite-plugin-uni/src/server/serve
rPlugin
MainJs.ts
→
packages/vite-plugin-uni/src/server/serveMainJs.ts
浏览文件 @
9e9456bb
import
path
from
'
path
'
import
{
ServerPlugin
,
readBody
}
from
'
vite
'
import
{
readBody
,
ViteDevServer
}
from
'
vite
'
import
{
getRoot
,
isMainJs
,
wrapperMainCode
}
from
'
../utils
'
export
const
serve
rPluginMainJs
:
ServerPlugin
=
({
app
,
root
}
)
=>
{
app
.
use
(
async
(
ctx
,
next
)
=>
{
export
const
serve
MainJs
=
(
server
:
ViteDevServer
)
=>
{
server
.
app
.
use
(
async
(
ctx
,
next
)
=>
{
await
next
()
if
(
isMainJs
(
ctx
.
path
))
{
const
body
=
await
readBody
(
ctx
.
body
)
...
...
packages/vite-plugin-uni/src/server/serve
rPlugin
PagesJson.ts
→
packages/vite-plugin-uni/src/server/servePagesJson.ts
浏览文件 @
9e9456bb
import
{
ServerPlugin
,
readBody
}
from
'
vite
'
import
{
ViteDevServer
}
from
'
vite
'
import
{
parsePagesJson
}
from
'
../utils
'
...
...
@@ -10,8 +10,8 @@ window.UniViewJSBridge = UniViewJSBridge
window.UniServiceJSBridge = UniServiceJSBridge
`
export
const
serve
rPluginPagesJson
:
ServerPlugin
=
({
app
}
)
=>
{
app
.
use
(
async
(
ctx
,
next
)
=>
{
export
const
serve
PagesJson
=
(
server
:
ViteDevServer
)
=>
{
server
.
app
.
use
(
async
(
ctx
,
next
)
=>
{
const
isPagesJson
=
ctx
.
path
.
endsWith
(
'
pages.json
'
)
if
(
isPagesJson
)
{
//skip serverPluginJson
...
...
packages/vite-plugin-uni/src/server/serverPluginEnv.ts
已删除
100644 → 0
浏览文件 @
3001efa9
import
{
ServerPlugin
}
from
'
vite
'
import
{
initEasycoms
}
from
'
../utils/easycomUtils
'
export
const
serverPluginEnv
:
ServerPlugin
=
({
root
,
watcher
})
=>
{
const
{
dirs
,
refresh
}
=
initEasycoms
(
root
)
watcher
.
on
(
'
all
'
,
(
eventName
,
path
)
=>
{
if
(
!
[
'
add
'
,
'
unlink
'
].
includes
(
eventName
))
{
return
}
if
(
dirs
.
find
(
dir
=>
path
.
startsWith
(
dir
)))
{
refresh
()
}
})
}
packages/vite-plugin-uni/src/utils/dynamicImport
Utils
.ts
→
packages/vite-plugin-uni/src/utils/dynamicImport.ts
浏览文件 @
9e9456bb
文件已移动
packages/vite-plugin-uni/src/utils/easycom
Utils
.ts
→
packages/vite-plugin-uni/src/utils/easycom.ts
浏览文件 @
9e9456bb
...
...
@@ -4,13 +4,13 @@ import { initEasycom } from '@dcloudio/uni-cli-shared'
export
function
initEasycoms
(
root
:
string
)
{
const
rootDir
=
path
.
resolve
(
root
,
'
src
'
)
const
dirs
=
[
'
components
'
].
map
(
dir
=>
path
.
resolve
(
rootDir
,
dir
))
const
dirs
=
[
'
components
'
].
map
(
(
dir
)
=>
path
.
resolve
(
rootDir
,
dir
))
const
easycomOptions
=
{
dirs
,
rootDir
:
rootDir
}
initEasycom
(
easycomOptions
)
return
{
dirs
,
refresh
()
{
initEasycom
(
easycomOptions
)
}
}
,
}
}
packages/vite-plugin-uni/src/utils/index.ts
浏览文件 @
9e9456bb
export
*
from
'
./mainJsUtils
'
export
*
from
'
./pagesJsonUtils
'
export
*
from
'
./dynamicImportUtils
'
export
*
from
'
./mainJs
'
export
*
from
'
./easycom
'
export
*
from
'
./transform
'
export
*
from
'
./pagesJson
'
export
*
from
'
./dynamicImport
'
packages/vite-plugin-uni/src/utils/mainJs
Utils
.ts
→
packages/vite-plugin-uni/src/utils/mainJs.ts
浏览文件 @
9e9456bb
import
path
from
'
path
'
import
slash
from
'
slash
'
import
{
dynamicImportCode
}
from
'
./dynamicImport
Utils
'
import
{
dynamicImportCode
}
from
'
./dynamicImport
'
const
MAIN_RE
=
/main.
[
jt
]
s/
...
...
packages/vite-plugin-uni/src/utils/pagesJson
Utils
.ts
→
packages/vite-plugin-uni/src/utils/pagesJson.ts
浏览文件 @
9e9456bb
...
...
@@ -46,7 +46,7 @@ function formatPages(pagesJson: Record<string, any>, jsonStr: string) {
function
removePlatformStyle
(
globalStyle
:
Record
<
string
,
any
>
)
{
delete
globalStyle
[
'
app-plus
'
]
delete
globalStyle
[
'
h5
'
]
Object
.
keys
(
globalStyle
).
forEach
(
name
=>
{
Object
.
keys
(
globalStyle
).
forEach
(
(
name
)
=>
{
if
(
name
.
startsWith
(
'
mp-
'
)
||
name
.
startsWith
(
'
quickapp
'
))
{
delete
globalStyle
[
name
]
}
...
...
@@ -85,7 +85,7 @@ function formatSubpackages(subpackages: SubpackagesOptions[]) {
function
formatPagesJson
(
jsonStr
:
string
)
{
let
pagesJson
:
Record
<
string
,
any
>
=
{
pages
:
[]
pages
:
[]
,
}
//TODO preprocess
try
{
...
...
@@ -116,14 +116,14 @@ function generatePageDefineCode(pageOptions: PageOptions) {
function
generatePagesDefineCode
(
pagesJson
:
Record
<
string
,
any
>
)
{
return
(
pagesJson
.
pages
as
PageOptions
[])
.
map
(
pageOptions
=>
generatePageDefineCode
(
pageOptions
))
.
map
(
(
pageOptions
)
=>
generatePageDefineCode
(
pageOptions
))
.
join
(
'
\n
'
)
}
function
formatPagesRoute
(
pagesJson
:
Record
<
string
,
any
>
):
PageRouteOptions
[]
{
const
firstPagePath
=
pagesJson
.
pages
[
0
].
path
const
tabBarList
=
(
pagesJson
.
tabBar
&&
pagesJson
.
tabBar
.
list
)
||
[]
return
(
pagesJson
.
pages
as
PageOptions
[]).
map
(
pageOptions
=>
{
return
(
pagesJson
.
pages
as
PageOptions
[]).
map
(
(
pageOptions
)
=>
{
const
path
=
pageOptions
.
path
const
name
=
formatPageIdentifier
(
path
)
const
isEntry
=
firstPagePath
===
path
?
true
:
undefined
...
...
@@ -142,14 +142,14 @@ function formatPagesRoute(pagesJson: Record<string, any>): PageRouteOptions[] {
windowTop
,
topWindow
:
props
.
topWindow
,
leftWindow
:
props
.
leftWindow
,
rightWindow
:
props
.
rightWindow
rightWindow
:
props
.
rightWindow
,
}
Object
.
assign
(
props
,
meta
)
return
{
name
,
path
:
pageOptions
.
path
,
props
,
meta
meta
,
}
})
}
...
...
@@ -169,13 +169,13 @@ function generatePageRoute({ name, path, props, meta }: PageRouteOptions) {
}
function
generatePagesRoute
(
pagesRouteOptions
:
PageRouteOptions
[])
{
return
pagesRouteOptions
.
map
(
pageOptions
=>
generatePageRoute
(
pageOptions
))
return
pagesRouteOptions
.
map
(
(
pageOptions
)
=>
generatePageRoute
(
pageOptions
))
}
function
generateRoutes
(
pagesJson
:
Record
<
string
,
any
>
)
{
return
[
`{ path: '/
${
pagesJson
.
pages
[
0
].
path
}
', redirect: '/' }`
,
...
generatePagesRoute
(
formatPagesRoute
(
pagesJson
))
...
generatePagesRoute
(
formatPagesRoute
(
pagesJson
))
,
]
}
...
...
packages/vite-plugin-uni/src/utils/transform.ts
0 → 100644
浏览文件 @
9e9456bb
import
path
from
'
path
'
import
debug
from
'
debug
'
import
{
TransformHook
}
from
'
rollup
'
const
debugPre
=
debug
(
'
uni:pre
'
)
const
extensions
=
[
'
.vue
'
,
'
.nvue
'
,
'
.js
'
,
'
.json
'
,
'
.css
'
]
export
const
transform
:
TransformHook
=
(
code
,
id
)
=>
{
const
extname
=
path
.
extname
(
id
)
if
(
!
extensions
.
includes
(
extname
))
{
return
}
// TODO
debugPre
(
id
)
return
code
}
scripts/build.js
浏览文件 @
9e9456bb
...
...
@@ -59,17 +59,21 @@ async function build(target) {
'
vite
'
,
[
'
build
'
,
'
--config
'
,
path
.
resolve
(
pkgDir
,
'
vite.config.ts
'
)],
{
stdio
:
'
inherit
'
stdio
:
'
inherit
'
,
}
)
}
else
if
(
bundler
===
'
tsc
'
)
{
return
await
execa
(
'
tsc
'
,
[
'
--listEmittedFiles
'
,
types
?
`--declaration`
:
''
,
'
-p
'
,
pkgDir
],
{
stdio
:
'
inherit
'
}
)
const
args
=
[
'
--listEmittedFiles
'
,
'
-p
'
,
path
.
resolve
(
pkgDir
,
'
tsconfig.json
'
),
]
if
(
types
)
{
args
.
push
(
'
--declaration
'
)
}
return
await
execa
(
'
tsc
'
,
args
,
{
stdio
:
'
inherit
'
,
})
}
await
execa
(
...
...
@@ -79,7 +83,7 @@ async function build(target) {
'
--environment
'
,
[
`NODE_ENV:
${
env
}
`
,
types
?
`TYPES:true`
:
``
,
`TARGET:
${
target
}
`
]
.
filter
(
Boolean
)
.
join
(
'
,
'
)
.
join
(
'
,
'
)
,
],
{
stdio
:
'
inherit
'
}
)
...
...
yarn.lock
浏览文件 @
9e9456bb
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录