提交 1e02476b 编写于 作者: Q qiang

fix: 解决开启 treeShaking 后 uni.previewImage 失效的问题 fixed #1168

上级 acdf149a
...@@ -31,6 +31,8 @@ const DEPS = { ...@@ -31,6 +31,8 @@ const DEPS = {
['/platforms/h5/components/system-routes/open-location/index.vue', 'OpenLocation'] ['/platforms/h5/components/system-routes/open-location/index.vue', 'OpenLocation']
], ],
'previewImage': [ 'previewImage': [
['/core/view/components/swiper/index.vue', 'Swiper'],
['/core/view/components/swiper-item/index.vue', 'SwiperItem'],
['/platforms/h5/components/system-routes/preview-image/index.vue', 'PreviewImage'] ['/platforms/h5/components/system-routes/preview-image/index.vue', 'PreviewImage']
], ],
'showToast': TOAST_DEPS, 'showToast': TOAST_DEPS,
...@@ -138,4 +140,4 @@ module.exports = { ...@@ -138,4 +140,4 @@ module.exports = {
JSON.stringify(manifestJson, null, 4) JSON.stringify(manifestJson, null, 4)
) )
} }
} }
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const updateComponents = require('./component')
const tmpDir = path.resolve(__dirname, '../../.tmp') const tmpDir = path.resolve(__dirname, '../../.tmp')
...@@ -72,6 +73,12 @@ function updateAppComponents(paths) { ...@@ -72,6 +73,12 @@ function updateAppComponents(paths) {
return updateExportDefaultObject(paths, 'app-components.js', false) return updateExportDefaultObject(paths, 'app-components.js', false)
} }
function updateCoreComponents(paths){
const tags = process.UNI_TAGS || new Set()
Object.keys(paths).forEach(tag => tags.add(tag.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()))
updateComponents(tags)
}
function updateAppMixins(paths) { function updateAppMixins(paths) {
return updateExportDefaultObject(paths, 'app-mixins.js', false, true) return updateExportDefaultObject(paths, 'app-mixins.js', false, true)
} }
...@@ -93,6 +100,11 @@ const isAppComponents = filepath => { ...@@ -93,6 +100,11 @@ const isAppComponents = filepath => {
filepath.indexOf('/platforms/' + process.env.UNI_PLATFORM + '/components/app/') === 0 filepath.indexOf('/platforms/' + process.env.UNI_PLATFORM + '/components/app/') === 0
} }
const isCoreComponents = filepath => {
return path.extname(filepath) === '.vue' &&
filepath.indexOf('/core/view/components/') === 0
}
const isAppMixins = filepath => { const isAppMixins = filepath => {
return path.extname(filepath) === '.js' && return path.extname(filepath) === '.js' &&
filepath.indexOf('/platforms/' + process.env.UNI_PLATFORM + '/components/app/') === 0 filepath.indexOf('/platforms/' + process.env.UNI_PLATFORM + '/components/app/') === 0
...@@ -113,6 +125,7 @@ function parseDeps(apis, manifest) { ...@@ -113,6 +125,7 @@ function parseDeps(apis, manifest) {
const apiProtocolPaths = Object.create(null) const apiProtocolPaths = Object.create(null)
const invokeApiPaths = Object.create(null) const invokeApiPaths = Object.create(null)
const appComponentsPaths = Object.create(null) const appComponentsPaths = Object.create(null)
const coreComponentsPaths = Object.create(null)
const appMixinsPaths = Object.create(null) const appMixinsPaths = Object.create(null)
const systemRoutesPaths = Object.create(null) const systemRoutesPaths = Object.create(null)
const apiSubscribePaths = Object.create(null) const apiSubscribePaths = Object.create(null)
...@@ -126,6 +139,9 @@ function parseDeps(apis, manifest) { ...@@ -126,6 +139,9 @@ function parseDeps(apis, manifest) {
}, { }, {
test: isAppComponents, test: isAppComponents,
paths: appComponentsPaths paths: appComponentsPaths
}, {
test: isCoreComponents,
paths: coreComponentsPaths
}, { }, {
test: isAppMixins, test: isAppMixins,
paths: appMixinsPaths paths: appMixinsPaths
...@@ -159,7 +175,7 @@ function parseDeps(apis, manifest) { ...@@ -159,7 +175,7 @@ function parseDeps(apis, manifest) {
}) })
if (strategy) { if (strategy) {
strategy.paths[exports] = filepath strategy.paths[exports] = filepath
} else { } else {
console.log('dep',name,dep) console.log('dep',name,dep)
console.warn(`${filepath} 未识别`) console.warn(`${filepath} 未识别`)
} }
...@@ -175,6 +191,7 @@ function parseDeps(apis, manifest) { ...@@ -175,6 +191,7 @@ function parseDeps(apis, manifest) {
apiProtocolPaths, apiProtocolPaths,
invokeApiPaths, invokeApiPaths,
appComponentsPaths, appComponentsPaths,
coreComponentsPaths,
appMixinsPaths, appMixinsPaths,
systemRoutesPaths, systemRoutesPaths,
apiSubscribePaths apiSubscribePaths
...@@ -203,6 +220,7 @@ module.exports = function updateApis(apis = new Set(), userApis = new Set()) { ...@@ -203,6 +220,7 @@ module.exports = function updateApis(apis = new Set(), userApis = new Set()) {
invokeApiPaths, invokeApiPaths,
apiSubscribePaths, apiSubscribePaths,
appComponentsPaths, appComponentsPaths,
coreComponentsPaths,
appMixinsPaths, appMixinsPaths,
systemRoutesPaths systemRoutesPaths
} = parseDeps(apis, manifest) } = parseDeps(apis, manifest)
...@@ -214,6 +232,7 @@ module.exports = function updateApis(apis = new Set(), userApis = new Set()) { ...@@ -214,6 +232,7 @@ module.exports = function updateApis(apis = new Set(), userApis = new Set()) {
updateInvokeApi(invokeApiPaths) updateInvokeApi(invokeApiPaths)
updateAppComponents(appComponentsPaths) updateAppComponents(appComponentsPaths)
updateCoreComponents(coreComponentsPaths)
updateAppMixins(appMixinsPaths) updateAppMixins(appMixinsPaths)
updateSystemRoutes(systemRoutesPaths) updateSystemRoutes(systemRoutesPaths)
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册