diff --git a/packages/uni-template-compiler/lib/auto-components.js b/packages/uni-template-compiler/lib/auto-components.js index 340547496b70fb5341d7d24830ab907db7b66632..388bdbb9615d9f1396f01065fd9dca9a4dc9ce88 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 -} +}