Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
83c79f2c
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,发现更多精彩内容 >>
提交
83c79f2c
编写于
12月 28, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(nvue): preprocess css
上级
f880e3a8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
17 deletion
+42
-17
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
...ges/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
+42
-17
未找到文件。
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
浏览文件 @
83c79f2c
...
...
@@ -28,7 +28,7 @@ import type Stylus from 'stylus'
import
type
Less
from
'
less
'
import
type
{
Alias
}
from
'
types/alias
'
import
{
transform
,
formatMessages
}
from
'
esbuild
'
import
{
preCss
}
from
'
../../../../preprocess
'
import
{
preCss
,
preNVueCss
}
from
'
../../../../preprocess
'
// const debug = createDebugger('vite:css')
export
interface
CSSOptions
{
...
...
@@ -372,7 +372,7 @@ function getCssResolversKeys(
async
function
compileCSS
(
id
:
string
,
code
:
string
,
config
:
ResolvedConfig
,
config
:
ResolvedConfig
&
{
nvue
?:
true
}
,
urlReplacer
:
CssUrlReplacer
,
atImportResolvers
:
CSSAtImportResolvers
,
server
?:
ViteDevServer
...
...
@@ -436,7 +436,8 @@ async function compileCSS(
code
,
config
.
root
,
opts
,
atImportResolvers
atImportResolvers
,
!!
config
.
nvue
)
if
(
preprocessResult
.
errors
.
length
)
{
throw
preprocessResult
.
errors
[
0
]
...
...
@@ -756,14 +757,16 @@ type StylePreprocessor = (
source
:
string
,
root
:
string
,
options
:
StylePreprocessorOptions
,
resolvers
:
CSSAtImportResolvers
resolvers
:
CSSAtImportResolvers
,
isNVue
:
boolean
)
=>
StylePreprocessorResults
|
Promise
<
StylePreprocessorResults
>
type
SassStylePreprocessor
=
(
source
:
string
,
root
:
string
,
options
:
SassStylePreprocessorOptions
,
resolvers
:
CSSAtImportResolvers
resolvers
:
CSSAtImportResolvers
,
isNVue
:
boolean
)
=>
StylePreprocessorResults
|
Promise
<
StylePreprocessorResults
>
export
interface
StylePreprocessorResults
{
...
...
@@ -804,13 +807,14 @@ const scss: SassStylePreprocessor = async (
source
,
root
,
options
,
resolvers
resolvers
,
isNVue
)
=>
{
const
render
=
loadPreprocessor
(
PreprocessLang
.
sass
,
root
).
render
const
internalImporter
:
Sass
.
Importer
=
(
url
,
importer
,
done
)
=>
{
resolvers
.
sass
(
url
,
importer
).
then
((
resolved
)
=>
{
if
(
resolved
)
{
rebaseUrls
(
resolved
,
options
.
filename
,
options
.
alias
).
then
(
done
)
rebaseUrls
(
resolved
,
options
.
filename
,
options
.
alias
,
isNVue
).
then
(
done
)
}
else
{
done
&&
done
(
null
)
}
...
...
@@ -856,7 +860,13 @@ const scss: SassStylePreprocessor = async (
}
}
const
sass
:
SassStylePreprocessor
=
(
source
,
root
,
options
,
aliasResolver
)
=>
const
sass
:
SassStylePreprocessor
=
(
source
,
root
,
options
,
aliasResolver
,
isNVue
)
=>
scss
(
source
,
root
,
...
...
@@ -864,12 +874,13 @@ const sass: SassStylePreprocessor = (source, root, options, aliasResolver) =>
...
options
,
indentedSyntax
:
true
,
},
aliasResolver
aliasResolver
,
isNVue
)
function
preprocessCss
(
content
:
string
)
{
function
preprocessCss
(
content
:
string
,
isNVue
:
boolean
=
false
)
{
if
(
content
.
includes
(
'
#endif
'
))
{
return
preCss
(
content
)
return
isNVue
?
preNVueCss
(
content
)
:
preCss
(
content
)
}
return
content
}
...
...
@@ -880,12 +891,13 @@ function preprocessCss(content: string) {
async
function
rebaseUrls
(
file
:
string
,
rootFile
:
string
,
alias
:
Alias
[]
alias
:
Alias
[],
isNVue
:
boolean
=
false
):
Promise
<
Sass
.
ImporterReturnType
>
{
file
=
path
.
resolve
(
file
)
// ensure os-specific flashes
// 条件编译
const
contents
=
preprocessCss
(
fs
.
readFileSync
(
file
,
'
utf-8
'
))
const
contents
=
preprocessCss
(
fs
.
readFileSync
(
file
,
'
utf-8
'
)
,
isNVue
)
// in the same dir, no need to rebase
const
fileDir
=
path
.
dirname
(
file
)
...
...
@@ -919,13 +931,20 @@ async function rebaseUrls(
}
// .less
const
less
:
StylePreprocessor
=
async
(
source
,
root
,
options
,
resolvers
)
=>
{
const
less
:
StylePreprocessor
=
async
(
source
,
root
,
options
,
resolvers
,
isNVue
)
=>
{
const
nodeLess
=
loadPreprocessor
(
PreprocessLang
.
less
,
root
)
const
viteResolverPlugin
=
createViteLessPlugin
(
nodeLess
,
options
.
filename
,
options
.
alias
,
resolvers
resolvers
,
isNVue
)
source
=
await
getSource
(
source
,
options
.
filename
,
options
.
additionalData
)
...
...
@@ -962,7 +981,8 @@ function createViteLessPlugin(
less
:
typeof
Less
,
rootFile
:
string
,
alias
:
Alias
[],
resolvers
:
CSSAtImportResolvers
resolvers
:
CSSAtImportResolvers
,
isNVue
:
boolean
):
Less
.
Plugin
{
if
(
!
ViteLessManager
)
{
ViteLessManager
=
class
ViteManager
extends
less
.
FileManager
{
...
...
@@ -996,7 +1016,12 @@ function createViteLessPlugin(
path
.
join
(
dir
,
'
*
'
)
)
if
(
resolved
)
{
const
result
=
await
rebaseUrls
(
resolved
,
this
.
rootFile
,
this
.
alias
)
const
result
=
await
rebaseUrls
(
resolved
,
this
.
rootFile
,
this
.
alias
,
isNVue
)
let
contents
:
string
if
(
result
&&
'
contents
'
in
result
)
{
contents
=
result
.
contents
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录