Skip to content

Commit 1e02476

Browse files
committed
fix: 解决开启 treeShaking 后 uni.previewImage 失效的问题 fixed #1168
1 parent acdf149 commit 1e02476

File tree

2 files changed

+24
-3
lines changed
  • build
  • packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin

2 files changed

+24
-3
lines changed

build/manifest.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const DEPS = {
3131
['/platforms/h5/components/system-routes/open-location/index.vue', 'OpenLocation']
3232
],
3333
'previewImage': [
34+
['/core/view/components/swiper/index.vue', 'Swiper'],
35+
['/core/view/components/swiper-item/index.vue', 'SwiperItem'],
3436
['/platforms/h5/components/system-routes/preview-image/index.vue', 'PreviewImage']
3537
],
3638
'showToast': TOAST_DEPS,
@@ -138,4 +140,4 @@ module.exports = {
138140
JSON.stringify(manifestJson, null, 4)
139141
)
140142
}
141-
}
143+
}

packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin/api.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs')
22
const path = require('path')
3+
const updateComponents = require('./component')
34

45
const tmpDir = path.resolve(__dirname, '../../.tmp')
56

@@ -72,6 +73,12 @@ function updateAppComponents(paths) {
7273
return updateExportDefaultObject(paths, 'app-components.js', false)
7374
}
7475

76+
function updateCoreComponents(paths){
77+
const tags = process.UNI_TAGS || new Set()
78+
Object.keys(paths).forEach(tag => tags.add(tag.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()))
79+
updateComponents(tags)
80+
}
81+
7582
function updateAppMixins(paths) {
7683
return updateExportDefaultObject(paths, 'app-mixins.js', false, true)
7784
}
@@ -93,6 +100,11 @@ const isAppComponents = filepath => {
93100
filepath.indexOf('/platforms/' + process.env.UNI_PLATFORM + '/components/app/') === 0
94101
}
95102

103+
const isCoreComponents = filepath => {
104+
return path.extname(filepath) === '.vue' &&
105+
filepath.indexOf('/core/view/components/') === 0
106+
}
107+
96108
const isAppMixins = filepath => {
97109
return path.extname(filepath) === '.js' &&
98110
filepath.indexOf('/platforms/' + process.env.UNI_PLATFORM + '/components/app/') === 0
@@ -113,6 +125,7 @@ function parseDeps(apis, manifest) {
113125
const apiProtocolPaths = Object.create(null)
114126
const invokeApiPaths = Object.create(null)
115127
const appComponentsPaths = Object.create(null)
128+
const coreComponentsPaths = Object.create(null)
116129
const appMixinsPaths = Object.create(null)
117130
const systemRoutesPaths = Object.create(null)
118131
const apiSubscribePaths = Object.create(null)
@@ -126,6 +139,9 @@ function parseDeps(apis, manifest) {
126139
}, {
127140
test: isAppComponents,
128141
paths: appComponentsPaths
142+
}, {
143+
test: isCoreComponents,
144+
paths: coreComponentsPaths
129145
}, {
130146
test: isAppMixins,
131147
paths: appMixinsPaths
@@ -159,7 +175,7 @@ function parseDeps(apis, manifest) {
159175
})
160176
if (strategy) {
161177
strategy.paths[exports] = filepath
162-
} else {
178+
} else {
163179
console.log('dep',name,dep)
164180
console.warn(`${filepath} 未识别`)
165181
}
@@ -175,6 +191,7 @@ function parseDeps(apis, manifest) {
175191
apiProtocolPaths,
176192
invokeApiPaths,
177193
appComponentsPaths,
194+
coreComponentsPaths,
178195
appMixinsPaths,
179196
systemRoutesPaths,
180197
apiSubscribePaths
@@ -203,6 +220,7 @@ module.exports = function updateApis(apis = new Set(), userApis = new Set()) {
203220
invokeApiPaths,
204221
apiSubscribePaths,
205222
appComponentsPaths,
223+
coreComponentsPaths,
206224
appMixinsPaths,
207225
systemRoutesPaths
208226
} = parseDeps(apis, manifest)
@@ -214,6 +232,7 @@ module.exports = function updateApis(apis = new Set(), userApis = new Set()) {
214232
updateInvokeApi(invokeApiPaths)
215233

216234
updateAppComponents(appComponentsPaths)
235+
updateCoreComponents(coreComponentsPaths)
217236
updateAppMixins(appMixinsPaths)
218237
updateSystemRoutes(systemRoutesPaths)
219-
}
238+
}

0 commit comments

Comments
 (0)