Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Velpro187
uni-app
提交
4b3d111b
U
uni-app
项目概览
Velpro187
/
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,发现更多精彩内容 >>
提交
4b3d111b
编写于
9月 16, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(cli): support sass-loader v8 #776
上级
e8bfd051
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
91 addition
and
89 deletion
+91
-89
packages/uni-cli-shared/lib/scss.js
packages/uni-cli-shared/lib/scss.js
+10
-1
packages/vue-cli-plugin-hbuilderx/build/css-loader.conf.js
packages/vue-cli-plugin-hbuilderx/build/css-loader.conf.js
+48
-11
packages/vue-cli-plugin-hbuilderx/build/utils.js
packages/vue-cli-plugin-hbuilderx/build/utils.js
+0
-71
packages/vue-cli-plugin-uni/lib/chain-webpack.js
packages/vue-cli-plugin-uni/lib/chain-webpack.js
+22
-2
packages/vue-cli-plugin-uni/lib/options.js
packages/vue-cli-plugin-uni/lib/options.js
+11
-4
未找到文件。
packages/uni-cli-shared/lib/scss.js
浏览文件 @
4b3d111b
const
semver
=
require
(
'
semver
'
)
let
sassLoaderVersion
try
{
sassLoaderVersion
=
semver
.
major
(
require
(
'
sass-loader/package.json
'
).
version
)
}
catch
(
e
)
{}
const
SCSS
=
`
$uni-color-primary: #007aff;
...
...
@@ -100,7 +107,9 @@ $uni-font-size-subtitle: 36rpx
$uni-color-paragraph: #3F536E // 文章段落颜色
$uni-font-size-paragraph: 30rpx
`
module
.
exports
=
{
SCSS
,
SASS
SASS
,
sassLoaderVersion
}
packages/vue-cli-plugin-hbuilderx/build/css-loader.conf.js
浏览文件 @
4b3d111b
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
{
// jsPreprocessOptions,
getPlatformScss
,
getPlatformSass
,
nvueCssPreprocessOptions
// htmlPreprocessOptions
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
sassLoaderVersion
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/scss
'
)
const
nvueStyleLoader
=
{
loader
:
'
@dcloudio/vue-cli-plugin-hbuilderx/packages/webpack-uni-nvue-loader/lib/style
'
}
...
...
@@ -17,19 +24,49 @@ const postcssLoader = {
loader
:
'
postcss-loader
'
,
options
:
{
sourceMap
:
false
,
parser
:
require
(
'
postcss-comment
'
),
plugins
:
[
require
(
'
postcss-import
'
),
require
(
'
@dcloudio/vue-cli-plugin-uni/packages/postcss
'
)
parser
:
require
(
'
postcss-comment
'
),
plugins
:
[
require
(
'
postcss-import
'
),
require
(
'
@dcloudio/vue-cli-plugin-uni/packages/postcss
'
)
]
}
}
// sass 全局变量
const
isSass
=
fs
.
existsSync
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
uni.sass
'
))
const
isScss
=
fs
.
existsSync
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
uni.scss
'
))
let
sassData
=
isSass
?
getPlatformSass
()
:
getPlatformScss
()
if
(
isSass
)
{
sassData
=
`@import "@/uni.sass"`
}
else
if
(
isScss
)
{
sassData
=
`
${
sassData
}
@import "@/uni.scss";`
}
const
scssLoader
=
{
loader
:
'
sass-loader
'
,
options
:
{
sourceMap
:
false
}
}
const
sassLoader
=
{
loader
:
'
sass-loader
'
,
options
:
{
sourceMap
:
false
,
data
:
''
sourceMap
:
false
}
}
if
(
sassLoaderVersion
<
8
)
{
scssLoader
.
options
.
data
=
sassData
sassLoader
.
options
.
data
=
sassData
sassLoader
.
options
.
indentedSyntax
=
true
}
else
{
scssLoader
.
options
.
prependData
=
sassData
sassLoader
.
options
.
prependData
=
sassData
sassLoader
.
options
.
sassOptions
=
{
indentedSyntax
:
true
}
}
...
...
@@ -48,11 +85,11 @@ const stylusLoader = {
}
}
function
createOneOf
(
preLoader
)
{
function
createOneOf
(
preLoader
)
{
const
use
=
[
nvueStyleLoader
,
preprocessLoader
]
]
use
.
push
(
postcssLoader
)
if
(
preLoader
)
{
use
.
push
(
preLoader
)
...
...
@@ -74,7 +111,7 @@ module.exports = [{
oneOf
:
createOneOf
()
},
{
test
:
/
\.
scss$/
,
oneOf
:
createOneOf
(
s
a
ssLoader
)
oneOf
:
createOneOf
(
s
c
ssLoader
)
},
{
test
:
/
\.
sass$/
,
oneOf
:
createOneOf
(
sassLoader
)
...
...
packages/vue-cli-plugin-hbuilderx/build/utils.js
已删除
100644 → 0
浏览文件 @
e8bfd051
function
resolve
(
module
)
{
try
{
return
require
.
resolve
(
module
)
}
catch
(
e
)
{}
return
module
}
exports
.
cssLoaders
=
function
(
options
)
{
options
=
options
||
{}
const
cssLoader
=
{
loader
:
resolve
(
'
css-loader
'
),
options
:
{
sourceMap
:
options
.
sourceMap
}
}
const
postcssLoader
=
{
loader
:
resolve
(
'
postcss-loader
'
),
options
:
{
sourceMap
:
options
.
sourceMap
}
}
// generate loader string to be used with extract text plugin
const
generateLoaders
=
(
loader
,
loaderOptions
)
=>
{
let
loaders
=
options
.
useVue
?
[
cssLoader
]
:
[]
if
(
options
.
usePostCSS
)
{
loaders
.
push
(
postcssLoader
)
}
if
(
loader
)
{
loaders
.
push
({
loader
:
resolve
(
loader
+
'
-loader
'
),
options
:
Object
.
assign
({},
loaderOptions
,
{
sourceMap
:
options
.
sourceMap
})
})
}
if
(
options
.
useVue
)
{
return
[
resolve
(
'
vue-style-loader
'
)].
concat
(
loaders
)
}
else
{
return
loaders
}
}
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
return
{
less
:
generateLoaders
(
'
less
'
),
sass
:
generateLoaders
(
'
sass
'
,
{
indentedSyntax
:
true
}),
scss
:
generateLoaders
(
'
sass
'
),
stylus
:
generateLoaders
(
'
stylus
'
),
styl
:
generateLoaders
(
'
stylus
'
)
}
}
// Generate loaders for standalone style files (outside of .vue)
exports
.
styleLoaders
=
function
(
options
)
{
const
output
=
[]
const
loaders
=
exports
.
cssLoaders
(
options
)
for
(
const
extension
in
loaders
)
{
const
loader
=
loaders
[
extension
]
output
.
push
({
test
:
new
RegExp
(
'
\\
.
'
+
extension
+
'
$
'
),
use
:
loader
})
}
return
output
}
packages/vue-cli-plugin-uni/lib/chain-webpack.js
浏览文件 @
4b3d111b
const
path
=
require
(
'
path
'
)
const
{
sassLoaderVersion
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/scss
'
)
function
resolve
(
dir
)
{
return
path
.
resolve
(
__dirname
,
'
..
'
,
dir
)
}
...
...
@@ -10,7 +14,7 @@ module.exports = function chainWebpack (platformOptions) {
cssPreprocessOptions
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
return
function
(
webpackConfig
)
{
return
function
(
webpackConfig
)
{
// 处理静态资源 limit
webpackConfig
.
module
.
rule
(
'
images
'
)
...
...
@@ -59,6 +63,22 @@ module.exports = function chainWebpack (platformOptions) {
})
})
if
(
sassLoaderVersion
>=
8
)
{
// check indentedSyntax
// vue cli 3 and sass-loader 8
cssTypes
.
forEach
(
type
=>
{
webpackConfig
.
module
.
rule
(
'
sass
'
).
oneOf
(
type
).
use
(
'
sass-loader
'
).
tap
(
options
=>
{
if
(
options
.
indentedSyntax
)
{
if
(
!
options
.
sassOptions
)
{
options
.
sassOptions
=
{}
}
options
.
sassOptions
.
indentedSyntax
=
true
delete
options
.
indentedSyntax
}
return
options
})
})
}
platformOptions
.
chainWebpack
(
webpackConfig
)
// define
webpackConfig
...
...
@@ -70,6 +90,6 @@ module.exports = function chainWebpack (platformOptions) {
if
(
runByHBuilderX
)
{
// 由 HBuilderX 运行时,移除进度,错误
webpackConfig
.
plugins
.
delete
(
'
progress
'
)
webpackConfig
.
plugins
.
delete
(
'
friendly-errors
'
)
}
}
}
}
packages/vue-cli-plugin-uni/lib/options.js
浏览文件 @
4b3d111b
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
{
sassLoaderVersion
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/scss
'
)
module
.
exports
=
function
initOptions
(
options
)
{
const
{
getPlatformScss
,
...
...
@@ -13,7 +17,7 @@ module.exports = function initOptions (options) {
// 增加 src/node_modules 解析
options
.
transpileDependencies
.
push
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
node_modules
'
))
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-
'
+
process
.
env
.
UNI_PLATFORM
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-
'
+
process
.
env
.
UNI_PLATFORM
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-stat
'
)
if
(
process
.
env
.
UNI_PLATFORM
===
'
app-plus
'
)
{
...
...
@@ -55,14 +59,17 @@ module.exports = function initOptions (options) {
let
sassData
=
isSass
?
getPlatformSass
()
:
getPlatformScss
()
if
(
isSass
)
{
sassData
=
`
${
sassData
}
@import "@/uni.sass"`
sassData
=
`@import "@/uni.sass"`
}
else
if
(
isScss
)
{
sassData
=
`
${
sassData
}
@import "@/uni.scss";`
}
options
.
css
.
loaderOptions
.
sass
.
data
=
sassData
if
(
sassLoaderVersion
<
8
)
{
options
.
css
.
loaderOptions
.
sass
.
data
=
sassData
}
else
{
options
.
css
.
loaderOptions
.
sass
.
prependData
=
sassData
}
let
userPostcssConfigPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
postcss.config.js
'
)
if
(
fs
.
existsSync
(
userPostcssConfigPath
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录