Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
78f41bbb
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
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,发现更多精彩内容 >>
提交
78f41bbb
编写于
5月 06, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: bin/uni.js
上级
7b12ab74
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
215 addition
and
20 deletion
+215
-20
packages/uni-h5/vite.config.ts
packages/uni-h5/vite.config.ts
+1
-3
packages/vite-plugin-uni/bin/uni.js
packages/vite-plugin-uni/bin/uni.js
+26
-0
packages/vite-plugin-uni/package.json
packages/vite-plugin-uni/package.json
+5
-0
packages/vite-plugin-uni/src/cli/index.ts
packages/vite-plugin-uni/src/cli/index.ts
+136
-0
packages/vite-plugin-uni/src/cli/utils.ts
packages/vite-plugin-uni/src/cli/utils.ts
+22
-0
packages/vite-plugin-uni/src/configResolved/plugins/cssScoped.ts
...s/vite-plugin-uni/src/configResolved/plugins/cssScoped.ts
+1
-1
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
+1
-1
packages/vite-plugin-uni/src/configResolved/plugins/inject.ts
...ages/vite-plugin-uni/src/configResolved/plugins/inject.ts
+2
-2
packages/vite-plugin-uni/src/configResolved/plugins/pageVue.ts
...ges/vite-plugin-uni/src/configResolved/plugins/pageVue.ts
+1
-1
packages/vite-plugin-uni/src/configResolved/plugins/pre.ts
packages/vite-plugin-uni/src/configResolved/plugins/pre.ts
+3
-3
packages/vite-plugin-uni/src/configResolved/plugins/preCss.ts
...ages/vite-plugin-uni/src/configResolved/plugins/preCss.ts
+2
-2
packages/vite-plugin-uni/src/configResolved/plugins/preVue.ts
...ages/vite-plugin-uni/src/configResolved/plugins/preVue.ts
+1
-1
packages/vite-plugin-uni/src/configResolved/plugins/renderjs.ts
...es/vite-plugin-uni/src/configResolved/plugins/renderjs.ts
+1
-1
packages/vite-plugin-uni/src/configResolved/plugins/static.ts
...ages/vite-plugin-uni/src/configResolved/plugins/static.ts
+1
-1
packages/vite-plugin-uni/src/configureServer/static.ts
packages/vite-plugin-uni/src/configureServer/static.ts
+1
-1
packages/vite-plugin-uni/src/handleHotUpdate/index.ts
packages/vite-plugin-uni/src/handleHotUpdate/index.ts
+1
-1
packages/vite-plugin-uni/src/resolveId/index.ts
packages/vite-plugin-uni/src/resolveId/index.ts
+1
-1
packages/vite-plugin-uni/src/utils/easycom.ts
packages/vite-plugin-uni/src/utils/easycom.ts
+1
-1
scripts/build.js
scripts/build.js
+3
-0
yarn.lock
yarn.lock
+5
-0
未找到文件。
packages/uni-h5/vite.config.ts
浏览文件 @
78f41bbb
...
...
@@ -115,9 +115,7 @@ export default defineConfig({
preserveEntrySignatures
:
'
strict
'
,
plugins
:
rollupPlugins
,
onwarn
:
(
msg
,
warn
)
=>
{
if
(
!
(
msg
.
message
||
msg
).
includes
(
'
external module "vue" but never used
'
)
)
{
if
(
!
String
(
msg
).
includes
(
'
external module "vue" but never used
'
))
{
warn
(
msg
)
}
},
...
...
packages/vite-plugin-uni/bin/uni.js
0 → 100755
浏览文件 @
78f41bbb
#!/usr/bin/env node
const
debugIndex
=
process
.
argv
.
findIndex
((
arg
)
=>
/^
(?:
-d|--debug
)
$/
.
test
(
arg
))
const
filterIndex
=
process
.
argv
.
findIndex
((
arg
)
=>
/^
(?:
-f|--filter
)
$/
.
test
(
arg
)
)
if
(
debugIndex
>
0
)
{
let
value
=
process
.
argv
[
debugIndex
+
1
]
if
(
!
value
||
value
.
startsWith
(
'
-
'
))
{
value
=
'
vite:*
'
}
else
{
// support debugging multiple flags with comma-separated list
value
=
value
.
split
(
'
,
'
)
.
map
((
v
)
=>
`vite:
${
v
}
`
)
.
join
(
'
,
'
)
}
process
.
env
.
DEBUG
=
value
if
(
filterIndex
>
0
)
{
const
filter
=
process
.
argv
[
filterIndex
+
1
]
if
(
filter
&&
!
filter
.
startsWith
(
'
-
'
))
{
process
.
env
.
VITE_DEBUG_FILTER
=
filter
}
}
}
require
(
'
../dist/cli
'
)
packages/vite-plugin-uni/package.json
浏览文件 @
78f41bbb
...
...
@@ -2,6 +2,9 @@
"name"
:
"@dcloudio/vite-plugin-uni"
,
"version"
:
"3.0.0"
,
"description"
:
"uni-app vite plugin"
,
"bin"
:
{
"uni"
:
"bin/uni.js"
},
"main"
:
"dist/index.js"
,
"types"
:
"dist/index.d.ts"
,
"files"
:
[
...
...
@@ -23,6 +26,8 @@
"dependencies"
:
{
"@rollup/pluginutils"
:
"^4.1.0"
,
"autoprefixer"
:
"^10.2.5"
,
"cac"
:
"^6.7.3"
,
"chalk"
:
"^4.1.1"
,
"debug"
:
"^4.3.1"
,
"estree-walker"
:
"^2.0.1"
,
"fs-extra"
:
"^9.0.1"
,
...
...
packages/vite-plugin-uni/src/cli/index.ts
0 → 100644
浏览文件 @
78f41bbb
import
{
cac
}
from
'
cac
'
import
chalk
from
'
chalk
'
import
{
LogLevel
,
ServerOptions
,
build
,
createServer
,
createLogger
,
BuildOptions
,
}
from
'
vite
'
import
{
initEnv
,
PLATFORMS
}
from
'
./utils
'
const
cli
=
cac
(
'
uni
'
)
export
interface
CliOptions
{
'
--
'
?:
string
[]
platform
?:
string
p
?:
string
ssr
?:
boolean
debug
?:
boolean
|
string
d
?:
boolean
|
string
filter
?:
string
f
?:
string
logLevel
?:
LogLevel
l
?:
LogLevel
clearScreen
?:
boolean
}
function
cleanOptions
(
options
:
CliOptions
)
{
const
ret
=
{
...
options
}
delete
ret
[
'
--
'
]
delete
ret
.
platform
delete
ret
.
p
delete
ret
.
ssr
delete
ret
.
debug
delete
ret
.
d
delete
ret
.
filter
delete
ret
.
f
delete
ret
.
logLevel
delete
ret
.
l
delete
ret
.
clearScreen
return
ret
}
cli
.
option
(
'
-p,--platform [platform]
'
,
'
[string]
'
+
PLATFORMS
.
join
(
'
|
'
),
{
default
:
'
h5
'
,
})
.
option
(
'
-ssr
'
,
'
[boolean] server-side rendering
'
,
{
default
:
false
,
})
.
option
(
'
-l, --logLevel <level>
'
,
`[string] silent | error | warn | all`
)
.
option
(
'
--clearScreen
'
,
`[boolean] allow/disable clear screen when logging`
)
.
option
(
'
-d, --debug [feat]
'
,
`[string | boolean] show debug logs`
)
.
option
(
'
-f, --filter <filter>
'
,
`[string] filter debug logs`
)
cli
.
command
(
''
)
.
alias
(
'
dev
'
)
.
option
(
'
--host [host]
'
,
`[string] specify hostname`
)
.
option
(
'
--port <port>
'
,
`[number] specify port`
)
.
option
(
'
--https
'
,
`[boolean] use TLS + HTTP/2`
)
.
option
(
'
--open [path]
'
,
`[boolean | string] open browser on startup`
)
.
option
(
'
--cors
'
,
`[boolean] enable CORS`
)
.
option
(
'
--strictPort
'
,
`[boolean] exit if specified port is already in use`
)
.
option
(
'
--force
'
,
`[boolean] force the optimizer to ignore the cache and re-bundle`
)
.
action
(
async
(
options
:
CliOptions
)
=>
{
initEnv
(
options
)
try
{
const
server
=
await
createServer
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
server
:
cleanOptions
(
options
)
as
ServerOptions
,
})
await
server
.
listen
()
}
catch
(
e
)
{
createLogger
(
options
.
logLevel
).
error
(
chalk
.
red
(
`error when starting dev server:\n
${
e
.
stack
}
`
)
)
process
.
exit
(
1
)
}
})
cli
.
command
(
'
build
'
)
.
option
(
'
--outDir <dir>
'
,
`[string] output directory (default: dist)`
)
.
option
(
'
--assetsInlineLimit <number>
'
,
`[number] static asset base64 inline threshold in bytes (default: 4096)`
)
.
option
(
'
--sourcemap
'
,
`[boolean] output source maps for build (default: false)`
)
.
option
(
'
--minify [minifier]
'
,
`[boolean | "terser" | "esbuild"] enable/disable minification, `
+
`or specify minifier to use (default: terser)`
)
.
option
(
'
--manifest
'
,
`[boolean] emit build manifest json`
)
.
option
(
'
--ssrManifest
'
,
`[boolean] emit ssr manifest json`
)
.
option
(
'
--emptyOutDir
'
,
`[boolean] force empty outDir when it's outside of root`
)
.
option
(
'
-m, --mode <mode>
'
,
`[string] set env mode`
)
.
option
(
'
-w, --watch
'
,
`[boolean] rebuilds when modules have changed on disk`
)
.
action
(
async
(
options
:
CliOptions
)
=>
{
initEnv
(
options
)
try
{
await
build
({
root
:
process
.
env
.
VITE_ROOT_DIR
,
logLevel
:
options
.
logLevel
,
clearScreen
:
options
.
clearScreen
,
build
:
cleanOptions
(
options
)
as
BuildOptions
,
})
}
catch
(
e
)
{
createLogger
(
options
.
logLevel
).
error
(
chalk
.
red
(
`error during build:\n
${
e
.
stack
}
`
)
)
process
.
exit
(
1
)
}
})
cli
.
help
()
cli
.
version
(
require
(
'
../../package.json
'
).
version
)
cli
.
parse
()
packages/vite-plugin-uni/src/cli/utils.ts
0 → 100644
浏览文件 @
78f41bbb
import
path
from
'
path
'
import
{
CliOptions
}
from
'
.
'
export
const
PLATFORMS
=
[
'
app
'
,
'
h5
'
,
'
mp-alipay
'
,
'
mp-baidu
'
,
'
mp-qq
'
,
'
mp-toutiao
'
,
'
mp-weixin
'
,
'
quickapp-webview-huawei
'
,
'
quickapp-webview-union
'
,
]
export
function
initEnv
(
options
:
CliOptions
)
{
process
.
env
.
VITE_ROOT_DIR
=
process
.
env
.
UNI_INPUT_DIR
||
process
.
cwd
()
process
.
env
.
UNI_INPUT_DIR
=
process
.
env
.
UNI_INPUT_DIR
||
path
.
resolve
(
process
.
cwd
(),
'
src
'
)
process
.
env
.
UNI_PLATFORM
=
options
.
platform
as
UniApp
.
PLATFORM
}
packages/vite-plugin-uni/src/configResolved/plugins/cssScoped.ts
浏览文件 @
78f41bbb
...
...
@@ -6,7 +6,7 @@ import { EXTNAME_VUE, parseVueRequest } from '@dcloudio/uni-cli-shared'
import
{
UniPluginFilterOptions
}
from
'
.
'
const
debugScoped
=
debug
(
'
uni:scoped
'
)
const
debugScoped
=
debug
(
'
vite:
uni:scoped
'
)
const
SCOPED_RE
=
/<style
\s[^
>
]
*scoped
[^
>
]
*>/i
...
...
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
浏览文件 @
78f41bbb
...
...
@@ -19,7 +19,7 @@ import { uniCssScopedPlugin } from './cssScoped'
import
{
uniRenderjsPlugin
}
from
'
./renderjs
'
import
{
uniPreVuePlugin
}
from
'
./preVue
'
const
debugPlugin
=
debug
(
'
uni:plugin
'
)
const
debugPlugin
=
debug
(
'
vite:
uni:plugin
'
)
export
interface
UniPluginFilterOptions
extends
VitePluginUniResolvedOptions
{
include
?:
FilterPattern
...
...
packages/vite-plugin-uni/src/configResolved/plugins/inject.ts
浏览文件 @
78f41bbb
...
...
@@ -51,8 +51,8 @@ export interface InjectOptions {
|
Function
}
const
debugInject
=
debug
(
'
uni:inject
'
)
const
debugInjectTry
=
debug
(
'
uni:inject-try
'
)
const
debugInject
=
debug
(
'
vite:
uni:inject
'
)
const
debugInjectTry
=
debug
(
'
vite:
uni:inject-try
'
)
export
function
uniInjectPlugin
(
options
:
InjectOptions
):
Plugin
{
if
(
!
options
)
throw
new
Error
(
'
Missing options
'
)
...
...
packages/vite-plugin-uni/src/configResolved/plugins/pageVue.ts
浏览文件 @
78f41bbb
...
...
@@ -6,7 +6,7 @@ import { Plugin } from 'vite'
import
{
parseVueRequest
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
../..
'
const
debugPageVue
=
debug
(
'
uni:page-vue
'
)
const
debugPageVue
=
debug
(
'
vite:
uni:page-vue
'
)
export
function
uniPageVuePlugin
(
options
:
VitePluginUniResolvedOptions
...
...
packages/vite-plugin-uni/src/configResolved/plugins/pre.ts
浏览文件 @
78f41bbb
...
...
@@ -11,9 +11,9 @@ import {
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniPluginFilterOptions
}
from
'
.
'
const
debugPreJs
=
debug
(
'
uni:pre-js
'
)
const
debugPreHtml
=
debug
(
'
uni:pre-html
'
)
const
debugPreJsTry
=
debug
(
'
uni:pre-js-try
'
)
const
debugPreJs
=
debug
(
'
vite:
uni:pre-js
'
)
const
debugPreHtml
=
debug
(
'
vite:
uni:pre-html
'
)
const
debugPreJsTry
=
debug
(
'
vite:
uni:pre-js-try
'
)
const
PRE_JS_EXTNAME
=
[
'
.json
'
,
'
.css
'
].
concat
(
EXTNAME_VUE
).
concat
(
EXTNAME_JS
)
const
PRE_HTML_EXTNAME
=
EXTNAME_VUE
...
...
packages/vite-plugin-uni/src/configResolved/plugins/preCss.ts
浏览文件 @
78f41bbb
...
...
@@ -5,8 +5,8 @@ import { preJs } from '@dcloudio/uni-cli-shared'
import
{
UniPluginFilterOptions
}
from
'
.
'
const
debugPre
=
debug
(
'
uni:pre-css
'
)
const
debugPreTry
=
debug
(
'
uni:pre-css-try
'
)
const
debugPre
=
debug
(
'
vite:
uni:pre-css
'
)
const
debugPreTry
=
debug
(
'
vite:
uni:pre-css-try
'
)
const
cssLangs
=
`\\.(less|sass|scss|styl|stylus|postcss)($|\\?)`
const
cssLangRE
=
new
RegExp
(
cssLangs
)
/**
...
...
packages/vite-plugin-uni/src/configResolved/plugins/preVue.ts
浏览文件 @
78f41bbb
...
...
@@ -11,7 +11,7 @@ import { parse } from '@vue/compiler-dom'
import
{
MagicString
}
from
'
@vue/compiler-sfc
'
import
{
EXTNAME_VUE
,
parseVueRequest
}
from
'
@dcloudio/uni-cli-shared
'
const
debugPreVue
=
debug
(
'
uni:pre-vue
'
)
const
debugPreVue
=
debug
(
'
vite:
uni:pre-vue
'
)
const
WXS_LANG_RE
=
/lang=
[
"|'
](
renderjs|wxs
)[
"|'
]
/
...
...
packages/vite-plugin-uni/src/configResolved/plugins/renderjs.ts
浏览文件 @
78f41bbb
...
...
@@ -4,7 +4,7 @@ import { rewriteDefault } from '@vue/compiler-sfc'
import
{
parseVueRequest
}
from
'
@dcloudio/uni-cli-shared
'
const
debugRenderjs
=
debug
(
'
uni:renderjs
'
)
const
debugRenderjs
=
debug
(
'
vite:
uni:renderjs
'
)
export
function
uniRenderjsPlugin
():
Plugin
{
return
{
...
...
packages/vite-plugin-uni/src/configResolved/plugins/static.ts
浏览文件 @
78f41bbb
...
...
@@ -5,7 +5,7 @@ import { cleanUrl } from '@dcloudio/uni-cli-shared'
import
{
UniPluginFilterOptions
}
from
'
.
'
import
{
createPublicFileFilter
}
from
'
../../utils
'
const
debugStatic
=
debug
(
'
uni:static
'
)
const
debugStatic
=
debug
(
'
vite:
uni:static
'
)
/**
* 提供static等目录静态资源加载
* @param _options
...
...
packages/vite-plugin-uni/src/configureServer/static.ts
浏览文件 @
78f41bbb
...
...
@@ -10,7 +10,7 @@ import { VitePluginUniResolvedOptions } from '..'
import
{
uniStaticMiddleware
}
from
'
./middlewares/static
'
import
{
createPublicFileFilter
}
from
'
../utils
'
const
debugStatic
=
debug
(
'
uni:static
'
)
const
debugStatic
=
debug
(
'
vite:
uni:static
'
)
/**
* devServer时提供static等目录的静态资源服务
* @param server
...
...
packages/vite-plugin-uni/src/handleHotUpdate/index.ts
浏览文件 @
78f41bbb
...
...
@@ -8,7 +8,7 @@ import { parseManifestJson, parsePagesJson } from '@dcloudio/uni-cli-shared'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
initEasycomsOnce
,
initFeatures
}
from
'
../utils
'
const
debugHmr
=
debug
(
'
uni:hmr
'
)
const
debugHmr
=
debug
(
'
vite:
uni:hmr
'
)
async
function
invalidate
(
file
:
string
,
moduleGraph
:
ModuleGraph
)
{
const
mods
=
await
moduleGraph
.
getModulesByFile
(
slash
(
file
))
...
...
packages/vite-plugin-uni/src/resolveId/index.ts
浏览文件 @
78f41bbb
...
...
@@ -4,7 +4,7 @@ import { Plugin } from 'vite'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
BUILT_IN_MODULES
}
from
'
../utils
'
const
debugResolve
=
debug
(
'
uni:resolve
'
)
const
debugResolve
=
debug
(
'
vite:
uni:resolve
'
)
export
function
createResolveId
(
_options
:
VitePluginUniResolvedOptions
...
...
packages/vite-plugin-uni/src/utils/easycom.ts
浏览文件 @
78f41bbb
...
...
@@ -22,7 +22,7 @@ interface EasycomCustom {
[
key
:
string
]:
string
}
export
const
debugEasycom
=
debug
(
'
uni:easycom
'
)
export
const
debugEasycom
=
debug
(
'
vite:
uni:easycom
'
)
const
easycoms
:
EasycomMatcher
[]
=
[]
...
...
scripts/build.js
浏览文件 @
78f41bbb
...
...
@@ -64,6 +64,9 @@ async function build(target) {
env
:
Object
.
assign
({
FORMAT
:
'
es
'
},
process
.
env
),
}
)
if
(
target
===
'
size-check
'
)
{
return
}
return
await
execa
(
'
vite
'
,
[
'
build
'
,
'
--config
'
,
path
.
resolve
(
pkgDir
,
'
vite.config.ts
'
)],
...
...
yarn.lock
浏览文件 @
78f41bbb
...
...
@@ -1676,6 +1676,11 @@ bytes-iec@^3.1.1:
resolved "https://registry.yarnpkg.com/bytes-iec/-/bytes-iec-3.1.1.tgz#94cd36bf95c2c22a82002c247df8772d1d591083"
integrity sha512-fey6+4jDK7TFtFg/klGSvNKJctyU7n2aQdnM+CO0ruLPbqqMOM8Tio0Pc+deqUeVKX1tL5DQep1zQ7+37aTAsA==
cac@^6.7.3:
version "6.7.3"
resolved "https://registry.yarnpkg.com/cac/-/cac-6.7.3.tgz#10410b8611677990cc2e3c8b576d471c1d71b768"
integrity sha512-ECVqVZh74qgSuZG9YOt2OJPI3wGcf+EwwuF/XIOYqZBD0KZYLtgPWqFPxmDPQ6joxI1nOlvVgRV6VT53Ooyocg==
cache-base@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录