diff --git a/packages/uni-cli-shared/lib/cache.js b/packages/uni-cli-shared/lib/cache.js
index f8a2223416619807fe034e371afd49e782f8e695..cbef08cd16519e43d70a689a50345954eda53c2a 100644
--- a/packages/uni-cli-shared/lib/cache.js
+++ b/packages/uni-cli-shared/lib/cache.js
@@ -82,9 +82,11 @@ function updateComponentJson (name, jsonObj, usingComponents = true, type = 'Com
const oldJsonStr = getJsonFile(name)
if (oldJsonStr) { // update
- if (usingComponents) { // merge usingComponents
+ if (usingComponents) { // merge usingComponents
+ // 其实直接拿新的 merge 到旧的应该就行
const oldJsonObj = JSON.parse(oldJsonStr)
- jsonObj.usingComponents = oldJsonObj.usingComponents || {}
+ jsonObj.usingComponents = oldJsonObj.usingComponents || {}
+ jsonObj.usingAutoImportComponents = oldJsonObj.usingAutoImportComponents || {}
if (oldJsonObj.usingGlobalComponents) { // 复制 global components(针对不支持全局 usingComponents 的平台)
jsonObj.usingGlobalComponents = oldJsonObj.usingGlobalComponents
}
@@ -118,6 +120,22 @@ function updateUsingGlobalComponents (name, usingGlobalComponents) {
}
}
+function updateUsingAutoImportComponents (name, usingAutoImportComponents) {
+ const oldJsonStr = getJsonFile(name)
+ if (oldJsonStr) { // update
+ const jsonObj = JSON.parse(oldJsonStr)
+ jsonObj.usingAutoImportComponents = usingAutoImportComponents
+ const newJsonStr = JSON.stringify(jsonObj, null, 2)
+ if (newJsonStr !== oldJsonStr) {
+ updateJsonFile(name, newJsonStr)
+ }
+ } else { // add
+ updateJsonFile(name, {
+ usingAutoImportComponents
+ })
+ }
+}
+
function updateUsingComponents (name, usingComponents, type) {
if (type === 'Component') {
componentSet.add(name)
@@ -260,7 +278,7 @@ module.exports = {
// 先简单处理,该方案不好,
// 后续为 pages-loader 增加 cache-loader,
// 然后其他修改 json 的地方也要定制 cache-loader
- store () {
+ store () {
const pagesJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
const filepath = path.resolve(
process.env.UNI_CLI_CONTEXT,
@@ -293,7 +311,7 @@ module.exports = {
clearCache()
} catch (e) {}
return
- }
+ }
const pagesJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
const mtimeMs = fs.statSync(pagesJsonPath).mtimeMs
const jsonCache = require(filepath)
@@ -328,6 +346,7 @@ module.exports = {
updateUsingComponents,
updateUsingGlobalComponents,
updateAppJsonUsingComponents,
+ updateUsingAutoImportComponents,
updateComponentGenerics,
updateGenericComponents,
getChangedJsonFileMap,
diff --git a/packages/uni-cli-shared/lib/pages.js b/packages/uni-cli-shared/lib/pages.js
index 181a4e7a4f83d309a1e790aac4c835c48a7fb84c..9e2ee2b3cf7a13603d73fa7e72cecaf5b9527e6f 100644
--- a/packages/uni-cli-shared/lib/pages.js
+++ b/packages/uni-cli-shared/lib/pages.js
@@ -308,7 +308,7 @@ function getGlobalUsingComponentsCode () {
return ''
}
return generateGlobalUsingComponentsCode(usingComponents)
-}
+}
function getUsingComponentsCode (pagePath) {
const usingComponents = usingComponentsPages[pagePath]
@@ -328,16 +328,16 @@ function addPageUsingComponents (pagePath, usingComponents) {
// 存储自动组件
const autoComponentMap = {}
-function addAutoComponent (name) {
- const options = process.UNI_AUTO_COMPONENTS
- const opt = options.find(opt => opt.test(name))
+function addAutoComponent (name) {
+ const options = process.UNI_AUTO_COMPONENTS
+ const opt = options.find(opt => opt.pattern.test(name))
if (!opt) { // 不匹配
return (autoComponentMap[name] = true) // cache
}
return (autoComponentMap[name] = {
name,
identifier: capitalize(camelize(name + '-auto-import')),
- source: name.replace(opt.test, opt.replacement)
+ source: name.replace(opt.pattern, opt.replacement)
})
}
@@ -363,8 +363,8 @@ module.exports = {
getPagesJson,
parsePagesJson,
pagesJsonJsFileName,
- getAutoComponents,
- addPageUsingComponents,
+ getAutoComponents,
+ addPageUsingComponents,
getUsingComponentsCode,
generateUsingComponentsCode,
getGlobalUsingComponentsCode,
diff --git a/packages/uni-migration/lib/mp-weixin/transform/template-transformer/transform/generate.js b/packages/uni-migration/lib/mp-weixin/transform/template-transformer/transform/generate.js
index 9a15454dec725d6418f666114c049c365c4c3384..2d0247df339bcb8a81382ad5aaee7472506f55e5 100644
--- a/packages/uni-migration/lib/mp-weixin/transform/template-transformer/transform/generate.js
+++ b/packages/uni-migration/lib/mp-weixin/transform/template-transformer/transform/generate.js
@@ -59,7 +59,7 @@ function genWxs(wxs, state) {
module.exports = function generate(node, state) {
return [
- `${genChildren(node).trim()}`,
+ `${genChildren(node).trim()}`,
...genWxs(state.wxs, state)
]
}
diff --git a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
index 7238037e808bf9ac48d39eaf995f71a264743665..176a3a263d85d7b1ac69971a065a144153e9a496 100644
--- a/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-extra.spec.js
@@ -310,7 +310,15 @@ describe('mp:compiler-extra', () => {
assertCodegen(
``,
``
- )
+ )
+ assertCodegen(
+ `
+
+
+
+ `,
+ ``
+ )
})
it('generate class binding', () => {
diff --git a/packages/uni-template-compiler/__tests__/demo.js b/packages/uni-template-compiler/__tests__/demo.js
index 58352526916c6470885b28ddad8e5702ef184a19..895122a8b3907d4b3452ee10008a9d507e27d439 100644
--- a/packages/uni-template-compiler/__tests__/demo.js
+++ b/packages/uni-template-compiler/__tests__/demo.js
@@ -1,11 +1,10 @@
const compiler = require('../lib')
const res = compiler.compile(
`
-
-
-
-
-
+
+
+
+
`, {
miniprogram: true,
diff --git a/packages/uni-template-compiler/lib/auto-components.js b/packages/uni-template-compiler/lib/auto-components.js
index 9220bbe3092dd05c815b89c11f52c75bc8773df3..0990389e62d27e719da6f4a3b3886021c9838cf5 100644
--- a/packages/uni-template-compiler/lib/auto-components.js
+++ b/packages/uni-template-compiler/lib/auto-components.js
@@ -1,12 +1,85 @@
+const path = require('path')
+
const {
isComponent
} = require('./util')
-module.exports = {
+const {
+ removeExt
+} = require('../../uni-cli-shared/lib/util')
+
+const {
+ getAutoComponents
+} = require('../../uni-cli-shared/lib/pages')
+
+const {
+ updateUsingAutoImportComponents
+} = require('../../uni-cli-shared/lib/cache')
+
+function formatSource (source) {
+ if (source.indexOf('@/') === 0) { // 根目录
+ source = source.replace('@/', '')
+ } else { // node_modules
+ source = 'node-modules/' + source
+ }
+ return removeExt(source)
+}
+
+function getWebpackChunkName (source) {
+ return formatSource(source)
+}
+
+function updateMPUsingAutoImportComponents (autoComponents, options) {
+ const resourcePath = options.resourcePath.replace(path.extname(options.resourcePath), '')
+ const usingAutoImportComponents = Object.create(null)
+ autoComponents.forEach(({
+ name,
+ source
+ }) => {
+ usingAutoImportComponents[name] = '/' + formatSource(source)
+ })
+ updateUsingAutoImportComponents(resourcePath, usingAutoImportComponents) // 更新json
+}
+
+function generateAutoComponentsCode (autoComponents, dynamic = false) {
+ const components = []
+ autoComponents.forEach(({
+ name,
+ source
+ }) => {
+ if (dynamic) {
+ components.push(`'${name}': ()=>import(/* webpackChunkName: "${getWebpackChunkName(source)}" */'${source}')`)
+ } else {
+ components.push(`'${name}': require('${source}').default`)
+ }
+ })
+ return `var components = {${components.join(',')}}`
+}
+
+function compileTemplate (source, options, compile) {
+ const res = compile(source, options)
+ const autoComponents = getAutoComponents([...(options.isUnaryTag.autoComponents || [])])
+ if (autoComponents.length) {
+ // console.log('检测到的自定义组件:' + JSON.stringify(autoComponents))
+ res.components = generateAutoComponentsCode(autoComponents, options.mp)
+ } else {
+ res.components = 'var components;'
+ }
+ if (options.mp) { // 小程序 更新 json 每次编译都要调整,保证热更新时增减组件一致
+ updateMPUsingAutoImportComponents(autoComponents || [], options)
+ }
+ return res
+}
+
+const compilerModule = {
preTransformNode (el, options) {
- if (isComponent(el.tag)) {
+ if (isComponent(el.tag) && el.tag !== 'App') { // App.vue
// 挂在 isUnaryTag 上边,可以保证外部访问到
(options.isUnaryTag.autoComponents || (options.isUnaryTag.autoComponents = new Set())).add(el.tag)
}
}
+}
+module.exports = {
+ compileTemplate,
+ module: compilerModule
}
diff --git a/packages/uni-template-compiler/lib/index.js b/packages/uni-template-compiler/lib/index.js
index 9ba87750e56180fbf12d0bc7da54f17e2f03086d..8989523d4a689fcce790959b46f6eeabadc0bc67 100644
--- a/packages/uni-template-compiler/lib/index.js
+++ b/packages/uni-template-compiler/lib/index.js
@@ -23,52 +23,44 @@ const compilerAlipayModule = require('./module-alipay')
const generateCodeFrame = require('./codeframe')
const {
- isComponent,
+ isComponent,
isUnaryTag
} = require('./util')
-function compileTemplate (source, options) {
- const res = compile(source, options)
- console.log(options)
- const {
- autoComponents
- } = options.isUnaryTag
- if (autoComponents) {
- console.log('检测到的自定义组件:' + [...autoComponents])
- }
- res.components = `{
- 'uni-badge': require('@components/uni-badge/uni-badge.vue').default,
- 'uni-tag': require('@components/uni-tag/uni-tag.vue').default
- }`
- return res
-}
+const {
+ module: autoComponentsModule,
+ compileTemplate
+} = require('./auto-components')
module.exports = {
compile (source, options = {}) {
- (options.modules || (options.modules = [])).push(require('./auto-components'))
- options.isUnaryTag = isUnaryTag
+ (options.modules || (options.modules = [])).push(autoComponentsModule)
+ options.isUnaryTag = isUnaryTag
+ // 将 autoComponents 挂在 isUnaryTag 上边
+ options.isUnaryTag.autoComponents = new Set()
+
options.preserveWhitespace = false
if (options.service) {
(options.modules || (options.modules = [])).push(require('./app/service'))
- options.optimize = false // 启用 staticRenderFns
+ options.optimize = false // 启用 staticRenderFns
// domProps => attrs
options.mustUseProp = () => false
options.isReservedTag = (tagName) => !isComponent(tagName) // 非组件均为内置
options.getTagNamespace = () => false
try {
- return compileTemplate(source, options)
+ return compileTemplate(source, options, compile)
} catch (e) {
console.error(source)
throw e
}
} else if (options.view) {
(options.modules || (options.modules = [])).push(require('./app/view'))
- options.optimize = false // 暂不启用 staticRenderFns
+ options.optimize = false // 暂不启用 staticRenderFns
options.isUnaryTag = isUnaryTag
options.isReservedTag = (tagName) => false // 均为组件
try {
- return compileTemplate(source, options)
+ return compileTemplate(source, options, compile)
} catch (e) {
console.error(source)
throw e
@@ -76,7 +68,7 @@ module.exports = {
}
if (!options.mp) { // h5
- return compileTemplate(source, options)
+ return compileTemplate(source, options, compile)
}
(options.modules || (options.modules = [])).push(compilerModule)
diff --git a/packages/uni-template-compiler/lib/template/generate.js b/packages/uni-template-compiler/lib/template/generate.js
index 403012a25033bfa927fe5e0f587314e0a72e8313..8d4e678a60406a82c1a23d2a71e3fd47d9e166b2 100644
--- a/packages/uni-template-compiler/lib/template/generate.js
+++ b/packages/uni-template-compiler/lib/template/generate.js
@@ -81,17 +81,17 @@ function genElement (ast, state, isRoot = false) {
const names = Object.keys(ast.attr)
const props = names.length
? ' ' +
- names
- .map(name => {
- if (name.includes(':else')) {
- return name
- }
- if (ast.attr[name] === '' && name !== 'value') { // value属性需要保留=''
- return name
- }
- return `${name}="${ast.attr[name]}"`
- })
- .join(' ')
+ names
+ .map(name => {
+ if (name.includes(':else')) {
+ return name
+ }
+ if (ast.attr[name] === '' && name !== 'value') { // value属性需要保留=''
+ return name
+ }
+ return `${name}="${ast.attr[name]}"`
+ })
+ .join(' ')
: ''
if (SELF_CLOSING_TAGS.includes(ast.type)) {
return `<${ast.type}${props}/>`
@@ -123,7 +123,7 @@ module.exports = function generate (ast, state) {
const replaceCodes = state.options.replaceCodes
if (replaceCodes) {
Object.keys(replaceCodes).forEach(key => {
- code = code.replace(key, replaceCodes[key])
+ code = code.replace(new RegExp(key.replace('$', '\\$'), 'g'), replaceCodes[key])
})
}
diff --git a/packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js b/packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js
index 2443bced74551b07181db7ba5b393a8f477bf5b5..44c2100d207b3110a610fc6c67b8d8b21996a9e9 100644
--- a/packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js
+++ b/packages/vue-cli-plugin-hbuilderx/build/vue-loader.conf.js
@@ -1,3 +1,12 @@
+const {
+ module: autoComponentsModule,
+ compileTemplate
+} = require('@dcloudio/uni-template-compiler/lib/auto-components')
+
+const {
+ isUnaryTag
+} = require('@dcloudio/uni-template-compiler/lib/util')
+
const TAGS = [
'ad',
'text',
@@ -92,10 +101,20 @@ if (process.env.UNI_USING_NVUE_COMPILER) {
})
}
+const compiler = require('weex-template-compiler')
+const oldCompile = compiler.compile
+compiler.compile = function (source, options = {}) {
+ (options.modules || (options.modules = [])).push(autoComponentsModule)
+ options.isUnaryTag = isUnaryTag
+ // 将 autoComponents 挂在 isUnaryTag 上边
+ options.isUnaryTag.autoComponents = new Set()
+ options.preserveWhitespace = false
+ return compileTemplate(source, options, oldCompile)
+}
+
module.exports = {
- preserveWhitespace: false,
isAppNVue: true,
- compiler: require('weex-template-compiler'),
+ compiler,
compilerOptions: {
modules
}
diff --git a/packages/vue-cli-plugin-uni/lib/app-plus/index.js b/packages/vue-cli-plugin-uni/lib/app-plus/index.js
index 6ada3f814c940e0594a1ffd644e3369038b31a02..73a155e8e463afb78b6987a7d90f1b770b8a64c2 100644
--- a/packages/vue-cli-plugin-uni/lib/app-plus/index.js
+++ b/packages/vue-cli-plugin-uni/lib/app-plus/index.js
@@ -234,7 +234,7 @@ const v3 = {
.rule('vue')
.test([/\.vue$/, /\.nvue$/])
.use('vue-loader') // service 层移除 style 节点,view 层返回固定 script
- .loader(path.resolve(__dirname, '../../packages/vue-loader/lib'))
+ .loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/vue-loader'))
.tap(options => Object.assign(options, {
isAppService,
isAppView,
diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js
index b9a840c6e944b752da8de80b59cdddd02aaead8a..02c09c86d58303dcfe569e6741cfdf111ae33962 100644
--- a/packages/vue-cli-plugin-uni/lib/env.js
+++ b/packages/vue-cli-plugin-uni/lib/env.js
@@ -256,6 +256,8 @@ const moduleAlias = require('module-alias')
moduleAlias.addAlias('vue-template-compiler', '@dcloudio/vue-cli-plugin-uni/packages/vue-template-compiler')
moduleAlias.addAlias('@megalo/template-compiler', '@dcloudio/vue-cli-plugin-uni/packages/@megalo/template-compiler')
moduleAlias.addAlias('mpvue-template-compiler', '@dcloudio/vue-cli-plugin-uni/packages/mpvue-template-compiler')
+// vue-loader
+moduleAlias.addAlias('vue-loader', '@dcloudio/vue-cli-plugin-uni/packages/vue-loader')
if (process.env.UNI_USING_V3 && process.env.UNI_PLATFORM === 'app-plus') {
moduleAlias.addAlias('vue-style-loader', '@dcloudio/vue-cli-plugin-uni/packages/app-vue-style-loader')
@@ -321,10 +323,8 @@ if (
}
process.UNI_AUTO_COMPONENTS = [{
- test (str) {
- return new RegExp('uni-(.*)').test(str)
- },
- replacement: '@components/uni-$1/uni-$1.vue'
+ pattern: new RegExp('uni-(.*)'),
+ replacement: '@/components/uni-$1/uni-$1.vue'
}]
runByHBuilderX && console.log(`正在编译中...`)
diff --git a/packages/vue-cli-plugin-uni/lib/vue-loader.js b/packages/vue-cli-plugin-uni/lib/vue-loader.js
index db5ba5d74e3ce4c9e02511334f97b421db039cd3..fc030cf1546381c334e658886cb2c7d7e1e44238 100644
--- a/packages/vue-cli-plugin-uni/lib/vue-loader.js
+++ b/packages/vue-cli-plugin-uni/lib/vue-loader.js
@@ -26,6 +26,7 @@ module.exports = function modifyVueLoader (webpackConfig, compilerOptions, api)
.rule('vue')
.test([/\.vue$/, /\.nvue$/])
.use('vue-loader')
+ .loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/vue-loader'))
.tap(options => Object.assign(options, {
compiler: getPlatformCompiler(),
compilerOptions: Object.assign({
diff --git a/packages/vue-cli-plugin-uni/packages/vue-loader/lib/codegen/styleInjection.js b/packages/vue-cli-plugin-uni/packages/vue-loader/lib/codegen/styleInjection.js
index 0e1cf0e737e38e1692259e9c64b9adc017936514..4e5ed92c946759179f8130b18ad7e3a901a6a4d4 100644
--- a/packages/vue-cli-plugin-uni/packages/vue-loader/lib/codegen/styleInjection.js
+++ b/packages/vue-cli-plugin-uni/packages/vue-loader/lib/codegen/styleInjection.js
@@ -9,7 +9,8 @@ module.exports = function genStyleInjectionCode (
resourcePath,
stringifyRequest,
needsHotReload,
- needsExplicitInjection // fixed by xxxxxx nvue 时,指定了 target 为 node,激活 needsExplicitInjection
+ needsExplicitInjection, // fixed by xxxxxx nvue 时,指定了 target 为 node,激活 needsExplicitInjection
+ platform
) {
let styleImportsCode = ``
let styleInjectionCode = ``
@@ -85,29 +86,42 @@ module.exports = function genStyleInjectionCode (
if (style.module) genCSSModulesCode(style, request, i)
}
})
- } else { // fixed by xxxxxx nvue style
- styleInjectionCode = `if(!this.options.style){
- this.options.style = {}
-}
-if(Vue.prototype.__merge_style && Vue.prototype.__$appStyle__){
- Vue.prototype.__merge_style(Vue.prototype.__$appStyle__, this.options.style)
-}
-`
- styles.forEach((style, i) => {
- if (isNotEmptyStyle(style)) {
- const request = genStyleRequest(style, i)
- styleInjectionCode += (
- `if(Vue.prototype.__merge_style){
- Vue.prototype.__merge_style(require(${request}).default, this.options.style)
- }else{
- Object.assign(this.options.style,require(${request}).default)
- }\n`//fixed by xxxxxx 简单处理,与 weex-vue-loader 保持一致
- //`var style${i} = require(${request})\n` +
- //`if (style${i}.__inject__) style${i}.__inject__(context)\n`
- )
- if (style.module) genCSSModulesCode(style, request, i)
+ } else { // fixed by xxxxxx (app-plus v3 view style and app-nvue style)
+ if (platform === 'app-vue') {
+ styles.forEach((style, i) => {
+ if (isNotEmptyStyle(style)) {
+ const request = genStyleRequest(style, i)
+ styleInjectionCode += (
+ `var style${i} = require(${request})\n` +
+ `if (style${i}.__inject__) style${i}.__inject__(context)\n`
+ )
+ if (style.module) genCSSModulesCode(style, request, i)
+ }
+ })
+ } else {
+ styleInjectionCode = `if(!this.options.style){
+ this.options.style = {}
}
- })
+ if(Vue.prototype.__merge_style && Vue.prototype.__$appStyle__){
+ Vue.prototype.__merge_style(Vue.prototype.__$appStyle__, this.options.style)
+ }
+ `
+ styles.forEach((style, i) => {
+ if (isNotEmptyStyle(style)) {
+ const request = genStyleRequest(style, i)
+ styleInjectionCode += (
+ `if(Vue.prototype.__merge_style){
+ Vue.prototype.__merge_style(require(${request}).default, this.options.style)
+ }else{
+ Object.assign(this.options.style,require(${request}).default)
+ }\n`//fixed by xxxxxx 简单处理,与 weex-vue-loader 保持一致
+ //`var style${i} = require(${request})\n` +
+ //`if (style${i}.__inject__) style${i}.__inject__(context)\n`
+ )
+ if (style.module) genCSSModulesCode(style, request, i)
+ }
+ })
+ }
}
if (!needsExplicitInjection && !hasCSSModules) {
diff --git a/packages/vue-cli-plugin-uni/packages/vue-loader/lib/index.js b/packages/vue-cli-plugin-uni/packages/vue-loader/lib/index.js
index 3b9ac9a4f0dd2cfc1766e01e0d8322e475d84ea5..b9023b0f7b4627b4e35e11c608ff1f6b8962615e 100644
--- a/packages/vue-cli-plugin-uni/packages/vue-loader/lib/index.js
+++ b/packages/vue-cli-plugin-uni/packages/vue-loader/lib/index.js
@@ -114,7 +114,7 @@ module.exports = function (source) {
let templateRequest
if (descriptor.template) {
// fixed by xxxxxx
- recyclable = options.isAppNVue && !!(template.attrs && template.attrs.recyclable)
+ recyclable = options.isAppNVue && !!(descriptor.template.attrs && descriptor.template.attrs.recyclable)
const src = descriptor.template.src || resourcePath
const idQuery = `&id=${id}`
const scopedQuery = hasScoped ? `&scoped=true` : ``
@@ -167,8 +167,8 @@ var component = normalizer(
${hasFunctional ? `true` : `false`},
${options.isAppNVue ? `null`: (/injectStyles/.test(stylesCode) ? `injectStyles` : `null`)},
${hasScoped ? JSON.stringify(id) : `null`},
- ${isServer ? JSON.stringify(hash(request)) : `null`}
- ${isShadow ? `,true` : ``},
+ ${isServer ? JSON.stringify(hash(request)) : `null`},
+ ${isShadow ? `true` : `false`},
components
)
`.trim() + `\n`
diff --git a/packages/vue-cli-plugin-uni/packages/vue-loader/lib/runtime/componentNormalizer.js b/packages/vue-cli-plugin-uni/packages/vue-loader/lib/runtime/componentNormalizer.js
index 6e2e9e764197816073831a6968ff03226b6643e4..9d816d259b82e57c2aa5043b52c5bf1ebc6533a8 100644
--- a/packages/vue-cli-plugin-uni/packages/vue-loader/lib/runtime/componentNormalizer.js
+++ b/packages/vue-cli-plugin-uni/packages/vue-loader/lib/runtime/componentNormalizer.js
@@ -12,13 +12,19 @@ export default function normalizeComponent (
injectStyles,
scopeId,
moduleIdentifier, /* server only */
- shadowMode /* vue-cli only */
+ shadowMode, /* vue-cli only */
+ components // fixed by xxxxxx auto components
) {
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
? scriptExports.options
: scriptExports
+ // fixed by xxxxxx auto components
+ if (components) {
+ options.components = Object.assign(components, options.components || {})
+ }
+
// render functions
if (render) {
options.render = render
diff --git a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/main.js b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/main.js
index cafd7f5b7a23353d1dad08f7a0ce334fe9927686..a2ee5fe0c79585302930a0e2acb2eda09cc0ccff 100644
--- a/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/main.js
+++ b/packages/vue-cli-plugin-uni/packages/webpack-uni-app-loader/view/main.js
@@ -81,7 +81,6 @@ function getStylesCode(loaderContext) {
(shortFilePath + '\n' + source) :
shortFilePath
)
-
stylesCode = genStylesCode(
loaderContext,
descriptor.styles,
@@ -89,7 +88,8 @@ function getStylesCode(loaderContext) {
resourcePath,
stringifyRequest,
needsHotReload,
- true // needs explicit injection?
+ true, // needs explicit injection?
+ 'app-vue'
)
}
return stylesCode.replace(/main\.js/g, 'App.vue')
diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
index c7d7ca3d774209292fe439b2a0342dbefa0060f5..46e18fda500826f62f9e342250e7dadc16b44a7b 100644
--- a/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
+++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js
@@ -91,14 +91,13 @@ module.exports = function generateJson (compilation) {
const jsonFileMap = getChangedJsonFileMap()
for (let name of jsonFileMap.keys()) {
const jsonObj = JSON.parse(jsonFileMap.get(name))
-
// customUsingComponents
- if (jsonObj.customUsingComponents && Object.keys(jsonObj.customUsingComponents)) {
+ if (jsonObj.customUsingComponents && Object.keys(jsonObj.customUsingComponents).length) {
jsonObj.usingComponents = Object.assign(jsonObj.customUsingComponents, jsonObj.usingComponents)
}
delete jsonObj.customUsingComponents
// usingGlobalComponents
- if (jsonObj.usingGlobalComponents && Object.keys(jsonObj.usingGlobalComponents)) {
+ if (jsonObj.usingGlobalComponents && Object.keys(jsonObj.usingGlobalComponents).length) {
jsonObj.usingComponents = Object.assign(jsonObj.usingGlobalComponents, jsonObj.usingComponents)
}
delete jsonObj.usingGlobalComponents
@@ -142,6 +141,12 @@ module.exports = function generateJson (compilation) {
delete jsonObj.genericComponents
+ // usingAutoImportComponents
+ if (jsonObj.usingAutoImportComponents && Object.keys(jsonObj.usingAutoImportComponents).length) {
+ jsonObj.usingComponents = Object.assign(jsonObj.usingAutoImportComponents, jsonObj.usingComponents)
+ }
+ delete jsonObj.usingAutoImportComponents
+
if (process.env.UNI_PLATFORM !== 'app-plus' && process.env.UNI_PLATFORM !== 'h5') {
delete jsonObj.navigationBarShadow
}