Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
e3800009
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e3800009
编写于
8月 02, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(vue-cli-plugin-uni): support webpack5
上级
05275209
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
160 addition
and
27 deletion
+160
-27
packages/vue-cli-plugin-uni/commands/build.js
packages/vue-cli-plugin-uni/commands/build.js
+5
-1
packages/vue-cli-plugin-uni/commands/serve.js
packages/vue-cli-plugin-uni/commands/serve.js
+58
-4
packages/vue-cli-plugin-uni/lib/app-plus/index.js
packages/vue-cli-plugin-uni/lib/app-plus/index.js
+8
-3
packages/vue-cli-plugin-uni/lib/chain-webpack.js
packages/vue-cli-plugin-uni/lib/chain-webpack.js
+17
-5
packages/vue-cli-plugin-uni/lib/configure-webpack.js
packages/vue-cli-plugin-uni/lib/configure-webpack.js
+34
-1
packages/vue-cli-plugin-uni/lib/h5/cssnano-options.js
packages/vue-cli-plugin-uni/lib/h5/cssnano-options.js
+11
-2
packages/vue-cli-plugin-uni/lib/h5/index.js
packages/vue-cli-plugin-uni/lib/h5/index.js
+6
-2
packages/vue-cli-plugin-uni/lib/mp/index.js
packages/vue-cli-plugin-uni/lib/mp/index.js
+5
-1
packages/vue-cli-plugin-uni/lib/options.js
packages/vue-cli-plugin-uni/lib/options.js
+16
-8
未找到文件。
packages/vue-cli-plugin-uni/commands/build.js
浏览文件 @
e3800009
const
path
=
require
(
'
path
'
)
const
webpack
=
require
(
'
webpack
'
)
const
{
runByHBuilderX
,
...
...
@@ -98,14 +99,18 @@ function getWebpackConfig (api, args, options) {
if
(
args
.
minimize
&&
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
modifyConfig
(
webpackConfig
,
config
=>
{
config
.
optimization
.
minimize
=
true
if
(
webpack
.
version
[
0
]
<=
4
)
{
config
.
optimization
.
namedModules
=
false
}
})
}
else
{
modifyConfig
(
webpackConfig
,
config
=>
{
if
(
!
config
.
optimization
)
{
config
.
optimization
=
{}
}
if
(
webpack
.
version
[
0
]
<=
4
)
{
config
.
optimization
.
namedModules
=
false
}
})
}
return
webpackConfig
...
...
@@ -131,7 +136,6 @@ function getWebpackConfigs (api, args, options) {
async
function
build
(
args
,
api
,
options
)
{
const
fs
=
require
(
'
fs-extra
'
)
const
chalk
=
require
(
'
chalk
'
)
const
webpack
=
require
(
'
webpack
'
)
const
{
log
,
...
...
packages/vue-cli-plugin-uni/commands/serve.js
浏览文件 @
e3800009
...
...
@@ -37,7 +37,7 @@ module.exports = (api, options) => {
const
url
=
require
(
'
url
'
)
const
path
=
require
(
'
path
'
)
const
chalk
=
require
(
'
chalk
'
)
const
{
chalk
}
=
require
(
'
@vue/cli-shared-utils
'
)
const
webpack
=
require
(
'
webpack
'
)
const
WebpackDevServer
=
require
(
'
webpack-dev-server
'
)
const
portfinder
=
require
(
'
portfinder
'
)
...
...
@@ -139,7 +139,56 @@ module.exports = (api, options) => {
const
compiler
=
webpack
(
webpackConfig
)
// create server
const
server
=
new
WebpackDevServer
(
compiler
,
Object
.
assign
({
let
server
if
(
webpack
.
version
[
0
]
>
4
)
{
server
=
new
WebpackDevServer
(
Object
.
assign
({
historyApiFallback
:
{
disableDotRule
:
true
,
rewrites
:
[{
from
:
/./
,
to
:
path
.
posix
.
join
(
options
.
publicPath
,
'
index.html
'
)
}]
},
hot
:
!
isProduction
,
compress
:
isProduction
,
static
:
{
directory
:
api
.
resolve
(
'
public
'
),
publicPath
:
options
.
publicPath
,
watch
:
!
isProduction
,
...
projectDevServerOptions
.
static
},
client
:
{
logging
:
'
none
'
,
overlay
:
isProduction
// TODO disable this
?
false
:
{
warnings
:
false
,
errors
:
true
},
progress
:
!
process
.
env
.
VUE_CLI_TEST
,
...
projectDevServerOptions
.
client
}
},
projectDevServerOptions
,
{
https
:
useHttps
,
proxy
:
proxySettings
,
setupMiddlewares
(
middlewares
,
devServer
)
{
// launch editor support.
// this works with vue-devtools & @vue/cli-overlay
devServer
.
app
.
use
(
'
/__open-in-editor
'
,
launchEditorMiddleware
(()
=>
console
.
log
(
`To specify an editor, specify the EDITOR env variable or `
+
`add "editor" field to your Vue project config.\n`
)))
// allow other plugins to register middlewares, e.g. PWA
// todo: migrate to the new API interface
api
.
service
.
devServerConfigFns
.
forEach
(
fn
=>
fn
(
devServer
.
app
,
devServer
))
if
(
projectDevServerOptions
.
setupMiddlewares
)
{
return
projectDevServerOptions
.
setupMiddlewares
(
middlewares
,
devServer
)
}
return
middlewares
}
}),
compiler
)
}
else
{
server
=
new
WebpackDevServer
(
compiler
,
Object
.
assign
({
clientLogLevel
:
'
none
'
,
historyApiFallback
:
{
disableDotRule
:
true
,
...
...
@@ -176,11 +225,12 @@ module.exports = (api, options) => {
server
)
}
}))
}
;
[
'
SIGINT
'
,
'
SIGTERM
'
].
forEach
(
signal
=>
{
process
.
on
(
signal
,
()
=>
{
server
.
close
(()
=>
{
server
[
webpack
.
version
[
0
]
>
4
?
'
stopCallback
'
:
'
close
'
]
(()
=>
{
process
.
exit
(
0
)
})
})
...
...
@@ -192,7 +242,7 @@ module.exports = (api, options) => {
process
.
stdin
.
on
(
'
data
'
,
data
=>
{
if
(
data
.
toString
()
===
'
close
'
)
{
console
.
log
(
'
got close signal!
'
)
server
.
close
(()
=>
{
server
[
webpack
.
version
[
0
]
>
4
?
'
stopCallback
'
:
'
close
'
]
(()
=>
{
process
.
exit
(
0
)
})
}
...
...
@@ -303,11 +353,15 @@ module.exports = (api, options) => {
server
.
showStatus
=
function
()
{}
}
if
(
webpack
.
version
[
0
]
>
4
)
{
server
.
start
().
catch
(
err
=>
reject
(
err
))
}
else
{
server
.
listen
(
port
,
host
,
err
=>
{
if
(
err
)
{
reject
(
err
)
}
})
}
})
})
}
...
...
packages/vue-cli-plugin-uni/lib/app-plus/index.js
浏览文件 @
e3800009
...
...
@@ -70,7 +70,11 @@ const v3 = {
webpackConfig
.
optimization
=
{}
}
// disable noEmitOnErrors
webpackConfig
.
optimization
.
noEmitOnErrors
=
false
if
(
webpack
.
version
[
0
]
>
4
)
{
webpackConfig
.
optimization
.
emitOnErrors
=
true
}
else
{
webpackConfig
.
optimization
.
noEmitOnErrors
=
false
}
if
(
isAppService
)
{
webpackConfig
.
optimization
.
runtimeChunk
=
{
...
...
@@ -134,7 +138,8 @@ const v3 = {
output
:
{
filename
:
'
[name].js
'
,
chunkFilename
:
'
[id].js
'
,
globalObject
:
'
this
'
// webpack5 use strict
globalObject
:
webpack
.
version
[
0
]
>
4
?
`(new Function("return this")())`
:
'
this
'
},
performance
:
{
hints
:
false
...
...
@@ -158,7 +163,7 @@ const v3 = {
compiler
:
vueLoader
.
compiler
,
before
:
[
beforeCode
+
require
(
'
../util
'
).
getAutomatorCode
()
+
statCode
+
pushCode
+
uniCloudCode
+
getGlobalUsingComponentsCode
()
getGlobalUsingComponentsCode
()
]
}
}]
...
...
packages/vue-cli-plugin-uni/lib/chain-webpack.js
浏览文件 @
e3800009
const
path
=
require
(
'
path
'
)
const
webpack
=
require
(
'
webpack
'
)
const
{
sassLoaderVersion
...
...
@@ -23,11 +24,22 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) {
const
urlLoader
=
require
(
'
@dcloudio/uni-cli-shared/lib/url-loader
'
)
const
staticTypes
=
[
'
images
'
,
'
media
'
,
'
fonts
'
]
staticTypes
.
forEach
(
staticType
=>
{
webpackConfig
.
module
.
rule
(
staticType
)
.
use
(
'
url-loader
'
)
.
loader
(
urlLoader
.
loader
)
.
tap
(
options
=>
Object
.
assign
(
options
,
urlLoader
.
options
()))
const
newOptions
=
urlLoader
.
options
()
if
(
webpack
.
version
[
0
]
>
4
)
{
if
(
'
limit
'
in
newOptions
)
{
webpackConfig
.
module
.
rule
(
staticType
).
parser
({
dataUrlCondition
:
{
maxSize
:
newOptions
.
limit
}
})
}
}
else
{
webpackConfig
.
module
.
rule
(
staticType
)
.
use
(
'
url-loader
'
)
.
loader
(
urlLoader
.
loader
)
.
tap
(
options
=>
Object
.
assign
(
options
,
newOptions
))
}
})
// 条件编译 vue 文件统一直接过滤html,js,css三种类型,单独资源文件引用各自过滤
...
...
packages/vue-cli-plugin-uni/lib/configure-webpack.js
浏览文件 @
e3800009
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
webpack
=
require
(
'
webpack
'
)
const
RuleSet
=
require
(
'
webpack/lib/RuleSet
'
)
const
CopyWebpackPlugin
=
require
(
'
copy-webpack-plugin
'
)
const
merge
=
require
(
'
webpack-merge
'
)
...
...
@@ -39,6 +38,37 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
return
(
rule
,
i
)
=>
{
const
clone
=
Object
.
assign
({},
rule
)
delete
clone
.
include
if
(
webpack
.
version
[
0
]
>
4
)
{
const
BasicEffectRulePlugin
=
require
(
'
webpack/lib/rules/BasicEffectRulePlugin
'
)
const
BasicMatcherRulePlugin
=
require
(
'
webpack/lib/rules/BasicMatcherRulePlugin
'
)
const
RuleSetCompiler
=
require
(
'
webpack/lib/rules/RuleSetCompiler
'
)
const
UseEffectRulePlugin
=
require
(
'
webpack/lib/rules/UseEffectRulePlugin
'
)
const
ruleSetCompiler
=
new
RuleSetCompiler
([
new
BasicMatcherRulePlugin
(
'
test
'
,
'
resource
'
),
new
BasicMatcherRulePlugin
(
'
include
'
,
'
resource
'
),
new
BasicMatcherRulePlugin
(
'
exclude
'
,
'
resource
'
,
true
),
new
BasicMatcherRulePlugin
(
'
resource
'
),
new
BasicMatcherRulePlugin
(
'
conditions
'
),
new
BasicMatcherRulePlugin
(
'
resourceQuery
'
),
new
BasicMatcherRulePlugin
(
'
realResource
'
),
new
BasicMatcherRulePlugin
(
'
issuer
'
),
new
BasicMatcherRulePlugin
(
'
compiler
'
),
new
BasicEffectRulePlugin
(
'
type
'
),
new
BasicEffectRulePlugin
(
'
sideEffects
'
),
new
BasicEffectRulePlugin
(
'
parser
'
),
new
BasicEffectRulePlugin
(
'
resolve
'
),
new
BasicEffectRulePlugin
(
'
generator
'
),
new
UseEffectRulePlugin
()
])
const
ruleSet
=
ruleSetCompiler
.
compile
([{
rules
:
[
clone
]
}])
const
rules
=
ruleSet
.
exec
({
resource
:
fakeFile
})
return
rules
.
length
>
0
&&
rule
.
use
}
else
{
const
RuleSet
=
require
(
'
webpack/lib/RuleSet
'
)
const
normalized
=
RuleSet
.
normalizeRule
(
clone
,
{},
''
)
return
(
!
rule
.
enforce
&&
...
...
@@ -47,6 +77,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
)
}
}
}
function
updateJsLoader
(
rawRules
,
fakeFile
,
checkLoaderRegex
,
loader
)
{
const
matchRule
=
rawRules
.
find
(
createMatcher
(
fakeFile
))
...
...
@@ -152,6 +183,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
if
(
Array
.
isArray
(
uses
))
{
if
(
uses
.
find
(
use
=>
babelLoaderRe
.
test
(
use
.
loader
)))
{
const
index
=
uses
.
findIndex
(
use
=>
cacheLoaderRe
.
test
(
use
.
loader
))
if
(
index
>=
0
)
{
if
(
process
.
env
.
UNI_USING_CACHE
)
{
Object
.
assign
(
uses
[
index
].
options
,
api
.
genCacheConfig
(
'
babel-loader/
'
+
process
.
env
.
UNI_PLATFORM
,
...
...
@@ -163,6 +195,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
}
}
}
}
// js preprocess
updateJsLoader
(
rawRules
,
'
foo.js
'
,
babelLoaderRe
,
{
...
...
packages/vue-cli-plugin-uni/lib/h5/cssnano-options.js
浏览文件 @
e3800009
const
{
getPlatformCssnano
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
webpack
=
require
(
'
webpack
'
)
module
.
exports
=
function
initCssnanoOptions
(
webpackConfig
)
{
const
module
=
webpackConfig
.
module
// TODO 临时 hack calc:false 看看 vue cli 后续是否开放 cssnano 的配置
const
cssnanoOptions
=
{
sourceMap
:
false
,
plugins
:
[
require
(
'
cssnano
'
)({
sourceMap
:
false
}
const
plugins
=
[
require
(
'
cssnano
'
)({
preset
:
[
'
default
'
,
getPlatformCssnano
()]
})]
// TODO postcss-loader version > 4
if
(
webpack
.
version
[
0
]
>
4
)
{
cssnanoOptions
.
postcssOptions
=
{
plugins
}
}
else
{
cssnanoOptions
.
plugins
=
plugins
}
module
.
rule
(
'
css
'
).
oneOf
(
'
vue-modules
'
).
use
(
'
cssnano
'
).
loader
(
'
postcss-loader
'
).
options
(
cssnanoOptions
)
...
...
packages/vue-cli-plugin-uni/lib/h5/index.js
浏览文件 @
e3800009
...
...
@@ -160,9 +160,13 @@ module.exports = {
},
plugins
,
optimization
:
{
moduleIds
:
'
hashed
'
moduleIds
:
webpack
.
version
[
0
]
>
4
?
'
deterministic
'
:
'
hashed
'
},
devServer
:
{
devServer
:
webpack
.
version
[
0
]
>
4
?
{
watchFiles
:
{
options
:
require
(
'
../util
'
).
getWatchOptions
()
}
}
:
{
watchOptions
:
require
(
'
../util
'
).
getWatchOptions
()
}
}
...
...
packages/vue-cli-plugin-uni/lib/mp/index.js
浏览文件 @
e3800009
...
...
@@ -157,7 +157,11 @@ module.exports = {
webpackConfig
.
optimization
=
{}
}
// disable noEmitOnErrors
webpackConfig
.
optimization
.
noEmitOnErrors
=
false
if
(
webpack
.
version
[
0
]
>
4
)
{
webpackConfig
.
optimization
.
emitOnErrors
=
true
}
else
{
webpackConfig
.
optimization
.
noEmitOnErrors
=
false
}
webpackConfig
.
optimization
.
runtimeChunk
=
{
name
:
'
common/runtime
'
...
...
packages/vue-cli-plugin-uni/lib/options.js
浏览文件 @
e3800009
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
webpack
=
require
(
'
webpack
'
)
const
isWin
=
/^win/
.
test
(
process
.
platform
)
...
...
@@ -23,11 +24,11 @@ module.exports = function initOptions (options) {
options
.
transpileDependencies
.
push
(
genTranspileDepRegex
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
node_modules
'
)))
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-
'
+
process
.
env
.
UNI_PLATFORM
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-i18n
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-stat
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-stat
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-push
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-app
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-cloud
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-stat
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-stat
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-push
'
)
if
(
process
.
env
.
UNI_PLATFORM
!==
'
mp-weixin
'
)
{
// mp runtime
...
...
@@ -59,8 +60,14 @@ module.exports = function initOptions (options) {
options
.
css
.
loaderOptions
.
sass
=
{}
}
if
(
!
options
.
css
.
loaderOptions
.
postcss
.
config
)
{
options
.
css
.
loaderOptions
.
postcss
.
config
=
{}
if
(
webpack
.
version
[
0
]
>
4
)
{
if
(
!
options
.
css
.
loaderOptions
.
postcss
.
postcssOptions
)
{
options
.
css
.
loaderOptions
.
postcss
.
postcssOptions
=
{}
}
}
else
{
if
(
!
options
.
css
.
loaderOptions
.
postcss
.
config
)
{
options
.
css
.
loaderOptions
.
postcss
.
config
=
{}
}
}
// sass 全局变量
...
...
@@ -85,9 +92,10 @@ module.exports = function initOptions (options) {
}
options
.
css
.
loaderOptions
.
sass
.
prependData
=
sassData
const
userPostcssConfigPath
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
postcss.config.js
'
)
if
(
fs
.
existsSync
(
userPostcssConfigPath
))
{
options
.
css
.
loaderOptions
.
postcss
.
config
.
path
=
userPostcssConfigPath
const
configPath
=
fs
.
existsSync
(
userPostcssConfigPath
)
?
userPostcssConfigPath
:
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
postcss.config.js
'
)
if
(
webpack
.
version
[
0
]
>
4
)
{
options
.
css
.
loaderOptions
.
postcss
.
postcssOptions
.
config
=
configPath
}
else
{
options
.
css
.
loaderOptions
.
postcss
.
config
.
path
=
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
postcss.config.js
'
)
options
.
css
.
loaderOptions
.
postcss
.
config
.
path
=
configPath
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录