From f4fd013c7deb1b450878b2d13cf3f5ad728687de Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 3 Dec 2020 17:50:07 +0800 Subject: [PATCH] chore(cli): remove tips with production --- .../lib/auto-components.js | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/uni-template-compiler/lib/auto-components.js b/packages/uni-template-compiler/lib/auto-components.js index 340547496..388bdbb96 100644 --- a/packages/uni-template-compiler/lib/auto-components.js +++ b/packages/uni-template-compiler/lib/auto-components.js @@ -63,23 +63,28 @@ function generateAutoComponentsCode (autoComponents, dynamic = false) { // 统一转换为驼峰命名 name = name.replace(/-(\w)/g, (_, str) => str.toUpperCase()) if (dynamic) { - components.push(`'${name}': function(){return import(/* webpackChunkName: "${getWebpackChunkName(source)}" */'${source}')}`) + components.push( + `'${name}': function(){return import(/* webpackChunkName: "${getWebpackChunkName(source)}" */'${source}')}` + ) } else { components.push(`'${name}': require('${source}').default`) } }) - return `var components; -try{ - components = {${components.join(',')}} -}catch(e){ - if(e.message.indexOf('Cannot find module') !== -1 && e.message.indexOf('.vue') !== -1){ - console.error(e.message) - console.error('1. 排查组件名称拼写是否正确') - console.error('2. 排查组件是否符合 easycom 规范,文档:https://uniapp.dcloud.net.cn/collocation/pages?id=easycom') - console.error('3. 若组件不符合 easycom 规范,需手动引入,并在 components 中注册该组件') - } else { - throw e - } + if (process.env.NODE_ENV === 'production') { + return `var components = {${components.join(',')}}` + } + return `var components; +try{ + components = {${components.join(',')}} +}catch(e){ + if(e.message.indexOf('Cannot find module') !== -1 && e.message.indexOf('.vue') !== -1){ + console.error(e.message) + console.error('1. 排查组件名称拼写是否正确') + console.error('2. 排查组件是否符合 easycom 规范,文档:https://uniapp.dcloud.net.cn/collocation/pages?id=easycom') + console.error('3. 若组件不符合 easycom 规范,需手动引入,并在 components 中注册该组件') + } else { + throw e + } }` } @@ -99,9 +104,9 @@ function compileTemplate (source, options, compile) { } const compilerModule = { - preTransformNode (el, options) { - if (el.tag === 'match-media' && process.env.UNI_PLATFORM !== 'mp-weixin') { - el.tag = 'uni-match-media' + preTransformNode (el, options) { + if (el.tag === 'match-media' && process.env.UNI_PLATFORM !== 'mp-weixin') { + el.tag = 'uni-match-media' } if (process.env.UNI_PLATFORM === 'quickapp-native') { // 排查所有标签 @@ -115,4 +120,4 @@ const compilerModule = { module.exports = { compileTemplate, module: compilerModule -} +} -- GitLab