From a593f763368e48137315e23604226dba6ee7b0ca Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 19 Dec 2019 19:09:30 +0800 Subject: [PATCH] feat(cli): auto import components --- lerna.json | 2 +- packages/uni-app-plus/dist/index.js | 2 +- packages/uni-mp-alipay/dist/index.js | 5 ++- packages/uni-mp-baidu/dist/index.js | 2 +- packages/uni-mp-qq/dist/index.js | 2 +- packages/uni-mp-toutiao/dist/index.js | 2 +- packages/uni-mp-weixin/dist/index.js | 2 +- .../lib/auto-components.js | 5 +++ packages/uni-template-compiler/lib/index.js | 2 +- packages/vue-cli-plugin-uni/lib/env.js | 37 ++++++------------- .../lib/platforms/mp-qq/index.js | 13 ++++--- 11 files changed, 35 insertions(+), 39 deletions(-) diff --git a/lerna.json b/lerna.json index febf5c43c7..c5c09024f4 100644 --- a/lerna.json +++ b/lerna.json @@ -12,5 +12,5 @@ "message": "chore(release): publish %s" } }, - "version": "2.0.0-alpha-24720191216006" + "version": "2.0.0-alpha-24720191216032" } diff --git a/packages/uni-app-plus/dist/index.js b/packages/uni-app-plus/dist/index.js index 3b1d09c21a..a7b7a15734 100644 --- a/packages/uni-app-plus/dist/index.js +++ b/packages/uni-app-plus/dist/index.js @@ -19,7 +19,7 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -function noop () {} +function noop () { } /** * Create a cached version of a pure function. diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index cabe08b67c..d1a96c45af 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -19,7 +19,7 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -function noop () {} +function noop () { } /** * Create a cached version of a pure function. @@ -751,6 +751,9 @@ const protocols = { // 需要做转换的 API 列表 }, showShareMenu: { name: 'showSharePanel' + }, + hideHomeButton: { + name: 'hideBackHome' } }; diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index 9809866267..8d92d8c53a 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -19,7 +19,7 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -function noop () {} +function noop () { } /** * Create a cached version of a pure function. diff --git a/packages/uni-mp-qq/dist/index.js b/packages/uni-mp-qq/dist/index.js index d926672b00..259cd9f96d 100644 --- a/packages/uni-mp-qq/dist/index.js +++ b/packages/uni-mp-qq/dist/index.js @@ -19,7 +19,7 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -function noop () {} +function noop () { } /** * Create a cached version of a pure function. diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index e49173489c..41e0b59a27 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -19,7 +19,7 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -function noop () {} +function noop () { } /** * Create a cached version of a pure function. diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index eed3ad93f4..6129401510 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -19,7 +19,7 @@ function hasOwn (obj, key) { return hasOwnProperty.call(obj, key) } -function noop () {} +function noop () { } /** * Create a cached version of a pure function. diff --git a/packages/uni-template-compiler/lib/auto-components.js b/packages/uni-template-compiler/lib/auto-components.js index 0990389e62..2ba431609c 100644 --- a/packages/uni-template-compiler/lib/auto-components.js +++ b/packages/uni-template-compiler/lib/auto-components.js @@ -20,6 +20,11 @@ function formatSource (source) { if (source.indexOf('@/') === 0) { // 根目录 source = source.replace('@/', '') } else { // node_modules + if (process.env.UNI_PLATFORM === 'mp-alipay') { + if (source.indexOf('@') === 0) { + source = source.replace('@', 'npm-scope-') + } + } source = 'node-modules/' + source } return removeExt(source) diff --git a/packages/uni-template-compiler/lib/index.js b/packages/uni-template-compiler/lib/index.js index 8989523d4a..bef2878f54 100644 --- a/packages/uni-template-compiler/lib/index.js +++ b/packages/uni-template-compiler/lib/index.js @@ -79,7 +79,7 @@ module.exports = { const res = compileTemplate(source, Object.assign(options, { optimize: false - })) + }), compile) options.mp.platform = platforms[options.mp.platform] diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js index 1780f406c2..99617975fd 100644 --- a/packages/vue-cli-plugin-uni/lib/env.js +++ b/packages/vue-cli-plugin-uni/lib/env.js @@ -267,20 +267,6 @@ if (process.env.UNI_PLATFORM === 'h5') { moduleAlias.addAlias('vue-style-loader', '@dcloudio/vue-cli-plugin-uni/packages/h5-vue-style-loader') } -// vue cache -if ( // 非 h5 ,非 v3,非 native - process.env.UNI_PLATFORM !== 'h5' && - !process.env.UNI_USING_V3 && - !process.env.UNI_USING_NATIVE -) { - moduleAlias.addAlias('./loaders/pitcher', (fromPath, request, alias) => { - if (fromPath.indexOf('vue-loader') !== -1) { - return require.resolve('@dcloudio/vue-cli-plugin-hbuilderx/packages/vue-loader/lib/loaders/pitcher') - } - return request - }) -} - if (process.env.UNI_PLATFORM === 'mp-toutiao') { // !important 始终带有一个空格 moduleAlias.addAlias( @@ -304,6 +290,18 @@ if (runByHBuilderX) { } } } + +// 组件自动导入配置 +process.UNI_AUTO_COMPONENTS = [] +const usingAutoImportComponents = pagesJsonObj.usingAutoImportComponents +if (usingAutoImportComponents) { + Object.keys(usingAutoImportComponents).forEach(pattern => { + process.UNI_AUTO_COMPONENTS.push({ + pattern: new RegExp(pattern), + replacement: usingAutoImportComponents[pattern] + }) + }) +} if ( process.env.UNI_USING_CACHE && @@ -321,17 +319,6 @@ if ( require('@dcloudio/uni-cli-shared/lib/cache').restore() } } -// 组件自动导入配置 -process.UNI_AUTO_COMPONENTS = [] -const usingAutoImportComponents = pagesJsonObj.usingAutoImportComponents -if (usingAutoImportComponents) { - Object.keys(usingAutoImportComponents).forEach(pattern => { - process.UNI_AUTO_COMPONENTS.push({ - pattern: new RegExp(pattern), - replacement: usingAutoImportComponents[pattern] - }) - }) -} runByHBuilderX && console.log(`正在编译中...`) diff --git a/packages/webpack-uni-pages-loader/lib/platforms/mp-qq/index.js b/packages/webpack-uni-pages-loader/lib/platforms/mp-qq/index.js index 3fed086b15..8ef907c6c4 100644 --- a/packages/webpack-uni-pages-loader/lib/platforms/mp-qq/index.js +++ b/packages/webpack-uni-pages-loader/lib/platforms/mp-qq/index.js @@ -5,12 +5,13 @@ module.exports = function (pagesJson, manifestJson) { } = require('../mp')(pagesJson, manifestJson, require('./project.config.json')) if (app.content && app.content.subPackages && app.content.subPackages.length === 0) { delete app.content.subPackages - } - - project.content.qqappid = project.content.appid - project.content.qqLibVersion = project.content.libVersion - delete project.content.appid - delete project.content.libVersion + } + if (project) { + project.content.qqappid = project.content.appid + project.content.qqLibVersion = project.content.libVersion + delete project.content.appid + delete project.content.libVersion + } return [app, project] } -- GitLab