提交 35ab3d58 编写于 作者: fxy060608's avatar fxy060608

fix(cli): remove duplicate log

上级 acd7e645
......@@ -12,7 +12,10 @@ const {
getTemplatePath
} = require('@dcloudio/uni-cli-shared')
const WebpackAppPlusNVuePlugin = require('../packages/webpack-app-plus-nvue-plugin')
const WebpackAppPlusNVuePlugin = process.env.UNI_USING_V3
? require('../packages/webpack-app-plus-plugin')
: require('../packages/webpack-app-plus-nvue-plugin')
const WebpackErrorsPlugin = require('@dcloudio/vue-cli-plugin-uni/packages/webpack-errors-plugin')
const WebpackUniMPPlugin = require('@dcloudio/webpack-uni-mp-loader/lib/plugin/index-new')
......@@ -72,8 +75,8 @@ const plugins = [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'VUE_APP_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
'UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'VUE_APP_PLATFORM': JSON.stringify(process.env.UNI_PLATFORM),
'UNI_CLOUD_PROVIDER': process.env.UNI_CLOUD_PROVIDER,
'HBX_USER_TOKEN': JSON.stringify(process.env.HBX_USER_TOKEN || '')
}
}),
......
......@@ -6,14 +6,18 @@ const {
done
} = require('@vue/cli-shared-utils')
let nvueCompiled = true
let serviceCompiled = true
let viewCompiled = true
const nvueChangedFiles = []
const serviceChangedFiles = []
const viewChangedFiles = []
let isFirst = true
let compiling = false
class WebpackAppPlusPlugin {
apply(compiler) {
if (process.env.UNI_USING_V3) {
......@@ -21,20 +25,27 @@ class WebpackAppPlusPlugin {
const chunkVersions = {}
const entry = compiler.options.entry()
const isAppService = entry['app-service']
const isAppView = entry['app-view']
const isAppService = !!entry['app-service']
const isAppView = !!entry['app-view']
const isAppNVue = !isAppService && !isAppView
compiler.hooks.invalid.tap('WebpackAppPlusPlugin', (fileName, changeTime) => {
if (!compiling) {
compiling = true
console.log('开始差量编译...')
}
})
compiler.hooks.beforeCompile.tapAsync('WebpackAppPlusPlugin', (params, callback) => {
isAppNVue && (nvueCompiled = false)
isAppService && (serviceCompiled = false)
isAppView && (viewCompiled = false)
callback()
})
compiler.hooks.emit.tapAsync('WebpackAppPlusPlugin', (compilation, callback) => {
isAppService && (serviceChangedFiles.length = 0)
isAppView && (viewChangedFiles.length = 0)
const changedChunks = compilation.chunks.filter(chunk => {
const oldVersion = chunkVersions[chunk.name]
chunkVersions[chunk.name] = chunk.hash
......@@ -47,6 +58,8 @@ class WebpackAppPlusPlugin {
!serviceChangedFiles.includes(file) && (serviceChangedFiles.push(file))
} else if (isAppView) {
!viewChangedFiles.includes(file) && (viewChangedFiles.push(file))
} else if (isAppNVue) {
!nvueChangedFiles.includes(file) && (nvueChangedFiles.push(file))
}
})
}
......@@ -56,14 +69,23 @@ class WebpackAppPlusPlugin {
compiler.hooks.done.tapPromise('WebpackAppPlusPlugin', compilation => {
return new Promise((resolve, reject) => {
isAppNVue && (nvueCompiled = true)
isAppService && (serviceCompiled = true)
isAppView && (viewCompiled = true)
if (serviceCompiled && viewCompiled) {
const changedFiles = [...new Set([...serviceChangedFiles, ...viewChangedFiles])]
if (serviceCompiled && viewCompiled && nvueCompiled) {
if (process.env.NODE_ENV === 'development') {
const changedFiles = [...new Set([
...serviceChangedFiles,
...viewChangedFiles,
...nvueChangedFiles
])]
if (!isFirst && changedFiles.length > 0) {
done(`Build complete. FILES:` + JSON.stringify(changedFiles))
if (serviceChangedFiles.length === 0 && viewChangedFiles.length === 0) {
// 仅 nvue 页面发生变化
done(`Build complete. PAGES:` + JSON.stringify(changedFiles))
} else {
done(`Build complete. FILES:` + JSON.stringify(changedFiles))
}
} else {
done(`Build complete. Watching for changes...`)
}
......@@ -71,8 +93,11 @@ class WebpackAppPlusPlugin {
} else {
done(`Build complete. `)
}
nvueChangedFiles.length = 0
serviceChangedFiles.length = 0
viewChangedFiles.length = 0
compiling = false
}
resolve()
})
})
......
......@@ -8,6 +8,8 @@ const {
initAutoImportScanComponents
} = require('@dcloudio/uni-cli-shared/lib/pages')
let compiling = false
class WebpackUniAppPlugin {
apply(compiler) {
if (process.UNI_CONFUSION) {
......@@ -32,6 +34,12 @@ class WebpackUniAppPlugin {
}
compiler.hooks.invalid.tap('webpack-uni-app-invalid', (fileName, changeTime) => {
if (!process.env.UNI_USING_V3) {
if (!compiling) {
compiling = true
console.log('开始差量编译...')
}
}
if (fileName && typeof fileName === 'string') {
if (fileName.indexOf('.vue') !== -1 || fileName.indexOf('.nvue') !== -1) {
if (process.UNI_AUTO_SCAN_COMPONENTS) {
......@@ -40,6 +48,15 @@ class WebpackUniAppPlugin {
}
}
})
// v3 版本在webpack-app-plus-plugin/index.js中处理,目前太乱了。后续要整理
if (!process.env.UNI_USING_V3) {
compiler.hooks.done.tapPromise('webpack-uni-app-done', compilation => {
return new Promise((resolve, reject) => {
compiling = false
resolve()
})
})
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册