diff --git a/lib/h5/ui.js b/lib/h5/ui.js new file mode 100644 index 0000000000000000000000000000000000000000..af49a44e2847e54223f277ee234005e341aad926 --- /dev/null +++ b/lib/h5/ui.js @@ -0,0 +1,24 @@ +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') diff --git a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js index e6be2ceb82d7844ce606579d085703ce8f513c25..0e2b930a31250796c2012c19688a53256b16bb42 100644 --- a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js +++ b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js @@ -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, diff --git a/packages/vue-cli-plugin-uni/lib/configure-webpack.js b/packages/vue-cli-plugin-uni/lib/configure-webpack.js index 77fc47d838d3e785e31ea32ac193a0463b7fd589..f32c89c84af03d1454d8862bd96d658095be59e9 100644 --- a/packages/vue-cli-plugin-uni/lib/configure-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/configure-webpack.js @@ -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 })) } diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js index 38f857544a88e6062e5ae8f5f80e4d6da97cb577..15768fc374abe5c6cba2a46aeea39024115380cf 100644 --- a/packages/vue-cli-plugin-uni/lib/env.js +++ b/packages/vue-cli-plugin-uni/lib/env.js @@ -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() diff --git a/packages/vue-cli-plugin-uni/util/on-errors.js b/packages/vue-cli-plugin-uni/util/on-errors.js index d12e4cfbe73d103226ce7e7069a179a39d61593c..c47019d8e14f51cff43f97aeacf8bd0e9db730f2 100644 --- a/packages/vue-cli-plugin-uni/util/on-errors.js +++ b/packages/vue-cli-plugin-uni/util/on-errors.js @@ -1,35 +1,4 @@ -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)) } diff --git a/packages/vue-cli-plugin-uni/util/on-warnings.js b/packages/vue-cli-plugin-uni/util/on-warnings.js new file mode 100644 index 0000000000000000000000000000000000000000..f86da04833be4c82587b3c40a6ef4d7c49f0c7e1 --- /dev/null +++ b/packages/vue-cli-plugin-uni/util/on-warnings.js @@ -0,0 +1,11 @@ +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)) + } +} diff --git a/packages/vue-cli-plugin-uni/util/stringify.js b/packages/vue-cli-plugin-uni/util/stringify.js new file mode 100644 index 0000000000000000000000000000000000000000..635dfb0dbfbecf9e69426af25018211d6fc24573 --- /dev/null +++ b/packages/vue-cli-plugin-uni/util/stringify.js @@ -0,0 +1,33 @@ +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')) +}