diff --git a/packages/uni-cli-shared/lib/pages.js b/packages/uni-cli-shared/lib/pages.js index a13820a4035d951f07c03bab7de90e630a1fbcdd..ca794991c65a9c9c85aa8f4827ba94ad4c20311a 100644 --- a/packages/uni-cli-shared/lib/pages.js +++ b/packages/uni-cli-shared/lib/pages.js @@ -334,21 +334,41 @@ let uniAutoImportComponents = [] let uniAutoImportScanComponents = [] -function initAutoImportScanComponents () { - const componentsPath = path.resolve(process.env.UNI_INPUT_DIR, 'components') +let uniQuickAppAutoImportScanComponents = false + +function getAutoComponentsByDir (componentsPath, absolute = false) { const components = {} try { fs.readdirSync(componentsPath).forEach(name => { - if (fs.existsSync(path.resolve(componentsPath, name, name + '.vue'))) { - components[`^${name}$`] = `@/components/${name}/${name}.vue` - } else if (fs.existsSync(path.resolve(componentsPath, name, name + '.nvue'))) { - components[`^${name}$`] = `@/components/${name}/${name}.nvue` + const folder = path.resolve(componentsPath, name) + const importDir = absolute ? normalizePath(folder) : `@/components/${name}` + if (fs.existsSync(path.resolve(folder, name + '.vue'))) { + components[`^${name}$`] = `${importDir}/${name}.vue` + } else if (fs.existsSync(path.resolve(folder, name + '.nvue'))) { + components[`^${name}$`] = `${importDir}/${name}.nvue` } }) } catch (e) {} + return components +} - uniAutoImportScanComponents = parseUsingAutoImportComponents(components) +function initAutoImportScanComponents () { + const componentsPath = path.resolve(process.env.UNI_INPUT_DIR, 'components') + + const components = getAutoComponentsByDir(componentsPath) + + if (process.env.UNI_PLATFORM === 'quickapp') { + if (!uniQuickAppAutoImportScanComponents) { + uniQuickAppAutoImportScanComponents = getAutoComponentsByDir( + path.resolve(require.resolve('@dcloudio/uni-quickapp'), '../../components'), + true + ) + } + // 平台内置组件优先级高 + Object.assign(components, uniQuickAppAutoImportScanComponents) + } + uniAutoImportScanComponents = parseUsingAutoImportComponents(components) refreshAutoComponentMap() } diff --git a/packages/uni-quickapp/package.json b/packages/uni-quickapp/package.json index 53b3a345cecba296579c3a02655e42d9c1547985..f0fc7fb227c6718bfc6cd79a9457dcb4719f3a45 100644 --- a/packages/uni-quickapp/package.json +++ b/packages/uni-quickapp/package.json @@ -1,7 +1,8 @@ { "name": "@dcloudio/uni-quickapp", "version": "2.0.0-alpha-24720191216006", - "description": "uni-app quickapp", + "description": "uni-app quickapp", + "main": "dist/vue.prod.js", "repository": { "type": "git", "url": "git+https://github.com/dcloudio/uni-app.git", diff --git a/packages/uni-template-compiler/lib/auto-components.js b/packages/uni-template-compiler/lib/auto-components.js index 5fea56b07af9b027795346f3b28c57f04cc5ebb7..da2a74f4f5dbb2e472141f3517e4141faab2a5e4 100644 --- a/packages/uni-template-compiler/lib/auto-components.js +++ b/packages/uni-template-compiler/lib/auto-components.js @@ -86,7 +86,10 @@ function compileTemplate (source, options, compile) { const compilerModule = { preTransformNode (el, options) { - if (isComponent(el.tag) && el.tag !== 'App') { // App.vue + if (process.env.UNI_PLATFORM === 'quickapp') { + // 排查所有标签 + (options.isUnaryTag.autoComponents || (options.isUnaryTag.autoComponents = new Set())).add(el.tag) + } else if (isComponent(el.tag) && el.tag !== 'App') { // App.vue // 挂在 isUnaryTag 上边,可以保证外部访问到 (options.isUnaryTag.autoComponents || (options.isUnaryTag.autoComponents = new Set())).add(el.tag) } @@ -95,4 +98,4 @@ const compilerModule = { module.exports = { compileTemplate, module: compilerModule -} +} diff --git a/packages/vue-cli-plugin-uni/packages/postcss/index.js b/packages/vue-cli-plugin-uni/packages/postcss/index.js index 0b1300e0351c9c07967df9c9e39444853f2da5d2..0b78b257366cb6a4221b7237117c4318cf8d7672 100644 --- a/packages/vue-cli-plugin-uni/packages/postcss/index.js +++ b/packages/vue-cli-plugin-uni/packages/postcss/index.js @@ -235,19 +235,20 @@ if (process.env.UNI_USING_V3) { // Transform each property declaration here decl.value = tranformValue(decl, opts) }) - - rule.selectors = rule.selectors.map(complexSelector => { - return transformSelector(complexSelector, simpleSelectors => { - return simpleSelectors.walkTags(tag => { - const k = tag.value - const v = CSS_TAGS[k] - if (v) { - tag.value = v === 'r' - ? `._${k}` : v - } - }) - }) - }) + if (process.env.UNI_PLATFORM !== 'quickapp') { + rule.selectors = rule.selectors.map(complexSelector => { + return transformSelector(complexSelector, simpleSelectors => { + return simpleSelectors.walkTags(tag => { + const k = tag.value + const v = CSS_TAGS[k] + if (v) { + tag.value = v === 'r' + ? `._${k}` : v + } + }) + }) + }) + } }) } }