提交 82dac631 编写于 作者: fxy060608's avatar fxy060608

fix(cli): refactor errors and warnings

上级 a4ab2e33
import Vue from 'vue'
// 使用白名单过滤(前期有一批自定义组件使用了 uni-)
import tags from 'uni-helpers/tags'
const oldIsReservedTag = Vue.config.isReservedTag
Vue.config.isReservedTag = function (tag) {
return tags.indexOf(tag) !== -1 || oldIsReservedTag(tag)
}
Vue.config.ignoredElements = tags
const oldGetTagNamespace = Vue.config.getTagNamespace
const conflictTags = ['switch', 'image', 'text', 'view']
Vue.config.getTagNamespace = function (tag) {
if (~conflictTags.indexOf(tag)) { // svg 部分标签名称与 uni 标签冲突
return false
}
return oldGetTagNamespace(tag) || false
}
require('uni-components')
......@@ -15,6 +15,7 @@ const WebpackErrorsPlugin = require('@dcloudio/vue-cli-plugin-uni/packages/webpa
const WebpackUniMPPlugin = require('@dcloudio/webpack-uni-mp-loader/lib/plugin/index-new')
const onErrors = require('@dcloudio/vue-cli-plugin-uni/util/on-errors')
const onWarnings = require('@dcloudio/vue-cli-plugin-uni/util/on-warnings')
const cssLoaders = require('./css-loader.conf')
const vueLoaderOptions = require('./vue-loader.conf')
......@@ -65,7 +66,8 @@ const plugins = [
}),
new webpack.ProvidePlugin(provide),
new WebpackErrorsPlugin({
onErrors
onErrors,
onWarnings
}),
new WebpackAppPlusNVuePlugin()
]
......@@ -192,12 +194,12 @@ module.exports = function () {
},
externals: {
'vue': 'Vue'
},
performance: {
hints: false
},
performance: {
hints: false
},
optimization: {
namedModules: false
namedModules: false
},
output: {
path: process.env.UNI_OUTPUT_DIR,
......
......@@ -190,9 +190,10 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
if (runByHBuilderX) { // 使用 HBuilderX 中运行时,调整错误日志输出
const WebpackErrorsPlugin = require('../packages/webpack-errors-plugin')
const onErrors = require('../util/on-errors')
const onWarnings = require('../util/on-warnings')
plugins.push(new WebpackErrorsPlugin({
onErrors,
onWarnings: onErrors
onWarnings
}))
}
......
......@@ -148,16 +148,9 @@ if (
platformOptions.uniStatistics || {}
)
if (
uniStatistics.enable !== false &&
(
process.env.NODE_ENV === 'production' ||
uniStatistics.enable === 'development'
)
) {
if (process.UNI_STAT_CONFIG.appid) {
process.env.UNI_USING_STAT = true
} else {
if (uniStatistics.enable !== false) {
process.env.UNI_USING_STAT = true
if (!process.UNI_STAT_CONFIG.appid && process.env.NODE_ENV === 'production') {
console.log()
console.warn(`当前应用未配置Appid,无法使用uni统计,详情参考:https://ask.dcloud.net.cn/article/36303`)
console.log()
......
const path = require('path')
const formatErrors = require('./format-errors')
const stringify = require('./stringify')
module.exports = function (errors) {
console.error(
Array.from(
new Set(
errors.map(err => {
const formatError = formatErrors[err.name]
if (formatError) {
const result = formatError(err)
if (result) {
if (typeof result === 'string') {
return result
} else {
const file = path.relative(process.env.UNI_INPUT_DIR, err.module.resource).split('?')[0]
if (file === 'pages.json') {
result.line = 1
}
return `${result.message} at ${file}:${result.line || 1}`
}
} else if (result === false) {
return '' // skip
}
}
return err.message
})
)
)
.filter(msg => !!msg)
.join('\n')
)
console.error(stringify(errors))
}
const stringify = require('./stringify')
module.exports = function (errors) {
const {
runByHBuilderX
} = require('@dcloudio/uni-cli-shared')
if (runByHBuilderX) {
console.log(stringify(errors))
} else {
console.warn(stringify(errors))
}
}
const path = require('path')
const formatErrors = require('./format-errors')
module.exports = function stringify (errors) {
return (Array.from(
new Set(
errors.map(err => {
const formatError = formatErrors[err.name]
if (formatError) {
const result = formatError(err)
if (result) {
if (typeof result === 'string') {
return result
} else {
const file = path.relative(process.env.UNI_INPUT_DIR, err.module.resource).split('?')[0]
if (file === 'pages.json') {
result.line = 1
}
return `${result.message} at ${file}:${result.line || 1}`
}
} else if (result === false) {
return '' // skip
}
}
return err.message
})
)
)
.filter(msg => !!msg)
.join('\n'))
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册