Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
58ddc008
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,发现更多精彩内容 >>
提交
58ddc008
编写于
5月 24, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add css plugin
上级
9a0fe6f7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
127 addition
and
39 deletion
+127
-39
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+17
-17
packages/vite-plugin-uni/src/configResolved/plugins/css.ts
packages/vite-plugin-uni/src/configResolved/plugins/css.ts
+44
-0
packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts
...ges/vite-plugin-uni/src/configResolved/plugins/easycom.ts
+36
-16
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
+30
-6
未找到文件。
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
58ddc008
...
@@ -485,7 +485,7 @@ var safeAreaInsets = {
...
@@ -485,7 +485,7 @@ var safeAreaInsets = {
onChange,
onChange,
offChange
offChange
};
};
var
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out = safeAreaInsets;
var out = safeAreaInsets;
const onEventPrevent = /* @__PURE__ */ withModifiers(() => {
const onEventPrevent = /* @__PURE__ */ withModifiers(() => {
}, ["prevent"]);
}, ["prevent"]);
const onEventStop = /* @__PURE__ */ withModifiers(() => {
const onEventStop = /* @__PURE__ */ withModifiers(() => {
...
@@ -497,10 +497,10 @@ function getWindowOffset() {
...
@@ -497,10 +497,10 @@ function getWindowOffset() {
const left = parseInt(style.getPropertyValue("--window-left"));
const left = parseInt(style.getPropertyValue("--window-left"));
const right = parseInt(style.getPropertyValue("--window-right"));
const right = parseInt(style.getPropertyValue("--window-right"));
return {
return {
top: top ? top +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top : 0,
top: top ? top + out.top : 0,
bottom: bottom ? bottom +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom : 0,
bottom: bottom ? bottom + out.bottom : 0,
left: left ? left +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.left : 0,
left: left ? left + out.left : 0,
right: right ? right +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right : 0
right: right ? right + out.right : 0
};
};
}
}
function updateCssVar(cssVars) {
function updateCssVar(cssVars) {
...
@@ -1194,7 +1194,7 @@ function normalizePageMeta(pageMeta) {
...
@@ -1194,7 +1194,7 @@ function normalizePageMeta(pageMeta) {
let offset = rpx2px(refreshOptions.offset);
let offset = rpx2px(refreshOptions.offset);
const {type} = navigationBar;
const {type} = navigationBar;
if (type !== "transparent" && type !== "none") {
if (type !== "transparent" && type !== "none") {
offset += NAVBAR_HEIGHT +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top;
offset += NAVBAR_HEIGHT + out.top;
}
}
refreshOptions.offset = offset;
refreshOptions.offset = offset;
refreshOptions.height = rpx2px(refreshOptions.height);
refreshOptions.height = rpx2px(refreshOptions.height);
...
@@ -15020,7 +15020,7 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
...
@@ -15020,7 +15020,7 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const windowWidth = getWindowWidth(screenWidth);
const windowWidth = getWindowWidth(screenWidth);
let windowHeight = window.innerHeight;
let windowHeight = window.innerHeight;
const language = navigator.language;
const language = navigator.language;
const statusBarHeight =
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top;
const statusBarHeight = out.top;
let osname;
let osname;
let osversion;
let osversion;
let model;
let model;
...
@@ -15133,12 +15133,12 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
...
@@ -15133,12 +15133,12 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const system = `${osname} ${osversion}`;
const system = `${osname} ${osversion}`;
const platform = osname.toLocaleLowerCase();
const platform = osname.toLocaleLowerCase();
const safeArea = {
const safeArea = {
left:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.left,
left: out.left,
right: windowWidth -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right,
right: windowWidth - out.right,
top:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top,
top: out.top,
bottom: windowHeight -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom,
bottom: windowHeight - out.bottom,
width: windowWidth -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right,
width: windowWidth -
out.left -
out.right,
height: windowHeight -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom
height: windowHeight -
out.top -
out.bottom
};
};
const {top: windowTop, bottom: windowBottom} = getWindowOffset();
const {top: windowTop, bottom: windowBottom} = getWindowOffset();
windowHeight -= windowTop;
windowHeight -= windowTop;
...
@@ -15158,10 +15158,10 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
...
@@ -15158,10 +15158,10 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
model,
model,
safeArea,
safeArea,
safeAreaInsets: {
safeAreaInsets: {
top:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top,
top: out.top,
right:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right,
right: out.right,
bottom:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom,
bottom: out.bottom,
left:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.left
left: out.left
}
}
};
};
});
});
...
...
packages/vite-plugin-uni/src/configResolved/plugins/css.ts
0 → 100644
浏览文件 @
58ddc008
import
fs
from
'
fs
'
import
{
OutputAsset
,
OutputChunk
}
from
'
rollup
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
resolveBuiltIn
}
from
'
@dcloudio/uni-cli-shared
'
export
const
buildInCssSet
=
new
Set
<
string
>
()
export
function
isCombineBuiltInCss
(
config
:
ResolvedConfig
)
{
return
config
.
command
===
'
build
'
&&
config
.
build
.
cssCodeSplit
}
export
function
uniCssPlugin
(
config
:
ResolvedConfig
):
Plugin
{
return
{
name
:
'
vite:uni-css
'
,
apply
:
'
build
'
,
generateBundle
(
_opts
,
bundle
)
{
if
(
!
isCombineBuiltInCss
(
config
)
||
!
buildInCssSet
.
size
)
{
return
}
const
chunks
=
Object
.
values
(
bundle
)
const
entryChunk
=
chunks
.
find
(
(
chunk
)
=>
chunk
.
type
===
'
chunk
'
&&
chunk
.
isEntry
)
as
OutputChunk
|
undefined
if
(
!
entryChunk
)
{
return
}
const
entryName
=
entryChunk
.
name
const
entryCssAsset
=
chunks
.
find
(
({
name
})
=>
name
===
entryName
+
'
.css
'
)
as
OutputAsset
if
(
entryCssAsset
)
{
entryCssAsset
.
source
+=
'
\n
'
+
generateBuiltInCssCode
([...
buildInCssSet
])
}
},
}
}
function
generateBuiltInCssCode
(
cssImports
:
string
[])
{
return
cssImports
.
map
((
cssImport
)
=>
fs
.
readFileSync
(
resolveBuiltIn
(
cssImport
),
'
utf8
'
))
.
join
(
'
\n
'
)
}
packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts
浏览文件 @
58ddc008
import
path
from
'
path
'
import
path
from
'
path
'
import
{
Plugin
}
from
'
vite
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
createFilter
}
from
'
@rollup/pluginutils
'
import
{
createFilter
}
from
'
@rollup/pluginutils
'
import
{
camelize
,
capitalize
}
from
'
@vue/shared
'
import
{
camelize
,
capitalize
}
from
'
@vue/shared
'
...
@@ -14,6 +14,7 @@ import {
...
@@ -14,6 +14,7 @@ import {
import
{
UniPluginFilterOptions
}
from
'
.
'
import
{
UniPluginFilterOptions
}
from
'
.
'
import
{
debugEasycom
,
matchEasycom
}
from
'
../../utils
'
import
{
debugEasycom
,
matchEasycom
}
from
'
../../utils
'
import
{
buildInCssSet
,
isCombineBuiltInCss
}
from
'
./css
'
const
H5_COMPONENTS_PATH
=
'
@dcloudio/uni-h5
'
const
H5_COMPONENTS_PATH
=
'
@dcloudio/uni-h5
'
...
@@ -51,8 +52,12 @@ const baseComponents = [
...
@@ -51,8 +52,12 @@ const baseComponents = [
const
identifierRE
=
/^
([
a-zA-Z_$
][
a-zA-Z
\\
d_$
]
*
)
$/
const
identifierRE
=
/^
([
a-zA-Z_$
][
a-zA-Z
\\
d_$
]
*
)
$/
export
function
uniEasycomPlugin
(
options
:
UniPluginFilterOptions
):
Plugin
{
export
function
uniEasycomPlugin
(
options
:
UniPluginFilterOptions
,
config
:
ResolvedConfig
):
Plugin
{
const
filter
=
createFilter
(
options
.
include
,
options
.
exclude
)
const
filter
=
createFilter
(
options
.
include
,
options
.
exclude
)
const
needCombineBuiltInCss
=
isCombineBuiltInCss
(
config
)
return
{
return
{
name
:
'
vite:uni-easycom
'
,
name
:
'
vite:uni-easycom
'
,
transform
(
code
,
id
)
{
transform
(
code
,
id
)
{
...
@@ -74,9 +79,22 @@ export function uniEasycomPlugin(options: UniPluginFilterOptions): Plugin {
...
@@ -74,9 +79,22 @@ export function uniEasycomPlugin(options: UniPluginFilterOptions): Plugin {
(
str
,
name
)
=>
{
(
str
,
name
)
=>
{
if
(
name
&&
!
name
.
startsWith
(
'
_
'
))
{
if
(
name
&&
!
name
.
startsWith
(
'
_
'
))
{
if
(
isBuiltInComponent
(
name
))
{
if
(
isBuiltInComponent
(
name
))
{
const
local
=
`__syscom_
${
i
++
}
`
if
(
needCombineBuiltInCss
)
{
// 发行模式下,应该将内置组件css输出到入口css中
resolveBuiltInCssImport
(
name
).
forEach
((
cssImport
)
=>
buildInCssSet
.
add
(
cssImport
)
)
return
addImportDeclaration
(
importDeclarations
,
local
,
H5_COMPONENTS_PATH
,
capitalize
(
camelize
(
name
))
)
}
return
addBuiltInImportDeclaration
(
return
addBuiltInImportDeclaration
(
importDeclarations
,
importDeclarations
,
`__syscom_
${
i
++
}
`
,
local
,
name
name
)
)
}
}
...
@@ -106,24 +124,26 @@ export function uniEasycomPlugin(options: UniPluginFilterOptions): Plugin {
...
@@ -106,24 +124,26 @@ export function uniEasycomPlugin(options: UniPluginFilterOptions): Plugin {
}
}
}
}
function
resolveBuiltInCssImport
(
name
:
string
)
{
const
cssImports
:
string
[]
=
[]
if
(
baseComponents
.
includes
(
name
))
{
cssImports
.
push
(
BASE_COMPONENTS_STYLE_PATH
+
name
+
'
.css
'
)
}
else
{
cssImports
.
push
(
H5_COMPONENTS_STYLE_PATH
+
name
+
'
.css
'
)
}
const
deps
=
COMPONENT_DEPS_CSS
[
name
as
keyof
typeof
COMPONENT_DEPS_CSS
]
deps
&&
deps
.
forEach
((
dep
)
=>
cssImports
.
push
(
dep
))
return
cssImports
}
function
addBuiltInImportDeclaration
(
function
addBuiltInImportDeclaration
(
importDeclarations
:
string
[],
importDeclarations
:
string
[],
local
:
string
,
local
:
string
,
name
:
string
name
:
string
)
{
)
{
if
(
baseComponents
.
includes
(
name
))
{
resolveBuiltInCssImport
(
name
).
forEach
((
cssImport
)
=>
importDeclarations
.
push
(
importDeclarations
.
push
(
`import '
${
cssImport
}
';`
)
`import '
${
BASE_COMPONENTS_STYLE_PATH
+
name
+
'
.css
'
}
';`
)
)
}
else
{
importDeclarations
.
push
(
`import '
${
H5_COMPONENTS_STYLE_PATH
+
name
+
'
.css
'
}
';`
)
}
const
deps
=
COMPONENT_DEPS_CSS
[
name
as
keyof
typeof
COMPONENT_DEPS_CSS
]
if
(
deps
)
{
deps
.
forEach
((
dep
)
=>
importDeclarations
.
push
(
`import '
${
dep
}
';`
))
}
return
addImportDeclaration
(
return
addImportDeclaration
(
importDeclarations
,
importDeclarations
,
local
,
local
,
...
...
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
浏览文件 @
58ddc008
...
@@ -24,6 +24,7 @@ import { uniRenderjsPlugin } from './renderjs'
...
@@ -24,6 +24,7 @@ import { uniRenderjsPlugin } from './renderjs'
import
{
uniPreVuePlugin
}
from
'
./preVue
'
import
{
uniPreVuePlugin
}
from
'
./preVue
'
import
{
uniSSRPlugin
}
from
'
./ssr
'
import
{
uniSSRPlugin
}
from
'
./ssr
'
import
{
uniResolveIdPlugin
}
from
'
./resolveId
'
import
{
uniResolveIdPlugin
}
from
'
./resolveId
'
import
{
uniCssPlugin
,
buildInCssSet
,
isCombineBuiltInCss
}
from
'
./css
'
const
debugPlugin
=
debug
(
'
vite:uni:plugin
'
)
const
debugPlugin
=
debug
(
'
vite:uni:plugin
'
)
...
@@ -70,7 +71,13 @@ const uniInjectPluginOptions: Partial<InjectOptions> = {
...
@@ -70,7 +71,13 @@ const uniInjectPluginOptions: Partial<InjectOptions> = {
getCurrentPages
:
[
'
@dcloudio/uni-h5
'
,
'
getCurrentPages
'
],
getCurrentPages
:
[
'
@dcloudio/uni-h5
'
,
'
getCurrentPages
'
],
UniServiceJSBridge
:
[
'
@dcloudio/uni-h5
'
,
'
UniServiceJSBridge
'
],
UniServiceJSBridge
:
[
'
@dcloudio/uni-h5
'
,
'
UniServiceJSBridge
'
],
UniViewJSBridge
:
[
'
@dcloudio/uni-h5
'
,
'
UniViewJSBridge
'
],
UniViewJSBridge
:
[
'
@dcloudio/uni-h5
'
,
'
UniViewJSBridge
'
],
callback
(
imports
,
mod
)
{
}
function
createUniInjectCallback
(
config
:
ResolvedConfig
):
InjectOptions
[
'
callback
'
]
{
const
needCombineBuiltInCss
=
isCombineBuiltInCss
(
config
)
return
(
imports
,
mod
)
=>
{
const
styles
=
const
styles
=
mod
[
0
]
===
'
@dcloudio/uni-h5
'
&&
mod
[
0
]
===
'
@dcloudio/uni-h5
'
&&
API_DEPS_CSS
[
mod
[
1
]
as
keyof
typeof
API_DEPS_CSS
]
API_DEPS_CSS
[
mod
[
1
]
as
keyof
typeof
API_DEPS_CSS
]
...
@@ -78,11 +85,15 @@ const uniInjectPluginOptions: Partial<InjectOptions> = {
...
@@ -78,11 +85,15 @@ const uniInjectPluginOptions: Partial<InjectOptions> = {
return
return
}
}
styles
.
forEach
((
style
)
=>
{
styles
.
forEach
((
style
)
=>
{
if
(
!
imports
.
has
(
style
))
{
if
(
needCombineBuiltInCss
)
{
imports
.
set
(
style
,
`import '
${
style
}
';`
)
buildInCssSet
.
add
(
style
)
}
else
{
if
(
!
imports
.
has
(
style
))
{
imports
.
set
(
style
,
`import '
${
style
}
';`
)
}
}
}
})
})
}
,
}
}
}
export
function
initPlugins
(
export
function
initPlugins
(
...
@@ -124,7 +135,15 @@ export function initPlugins(
...
@@ -124,7 +135,15 @@ export function initPlugins(
// 可以考虑使用apply:'build'
// 可以考虑使用apply:'build'
if
(
command
===
'
build
'
)
{
if
(
command
===
'
build
'
)
{
addPlugin
(
plugins
,
uniInjectPlugin
(
uniInjectPluginOptions
),
'
vite:vue
'
)
addPlugin
(
plugins
,
uniInjectPlugin
(
extend
(
uniInjectPluginOptions
,
{
callback
:
createUniInjectCallback
(
config
),
})
),
'
vite:vue
'
)
}
}
addPlugin
(
addPlugin
(
...
@@ -135,12 +154,17 @@ export function initPlugins(
...
@@ -135,12 +154,17 @@ export function initPlugins(
addPlugin
(
addPlugin
(
plugins
,
plugins
,
uniEasycomPlugin
(
extend
(
uniEasycomPluginOptions
,
options
)),
uniEasycomPlugin
(
extend
(
uniEasycomPluginOptions
,
options
)
,
config
),
'
vite:vue
'
'
vite:vue
'
)
)
addPlugin
(
plugins
,
uniPageVuePlugin
(
options
),
'
vite:vue
'
)
addPlugin
(
plugins
,
uniPageVuePlugin
(
options
),
'
vite:vue
'
)
addPlugin
(
plugins
,
uniJsonPlugin
(
options
),
'
vite:json
'
,
'
pre
'
)
addPlugin
(
plugins
,
uniJsonPlugin
(
options
),
'
vite:json
'
,
'
pre
'
)
addPlugin
(
plugins
,
uniStaticPlugin
(
options
,
config
),
'
vite:asset
'
,
'
pre
'
)
addPlugin
(
plugins
,
uniStaticPlugin
(
options
,
config
),
'
vite:asset
'
,
'
pre
'
)
if
(
isCombineBuiltInCss
(
config
))
{
addPlugin
(
plugins
,
uniCssPlugin
(
config
),
'
vite:asset
'
)
}
if
(
command
===
'
build
'
&&
!
config
.
build
.
ssr
)
{
if
(
command
===
'
build
'
&&
!
config
.
build
.
ssr
)
{
addPlugin
(
plugins
,
uniCopyPlugin
(
options
),
plugins
.
length
)
addPlugin
(
plugins
,
uniCopyPlugin
(
options
),
plugins
.
length
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录