Skip to content

Commit f872023

Browse files
committed
Perf: 细节
1 parent 7792610 commit f872023

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

build/development.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ module.exports = function(config) {
5151
// },
5252
// ])
5353
// 补全html插入资源
54-
config.plugin('insert-preload').use(require.resolve('./insertPreload.js'))
54+
config
55+
.plugin('insert-preload')
56+
.use(require.resolve('./insertPreload.js'), [
57+
{ noPreload: true, noPrefetch: true },
58+
])
5559
// stylelint
5660
config.plugin('stylelint').use('stylelint-webpack-plugin', [
5761
{

src/utils/downloader.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,27 @@ function download(url: string, query?: IObject, name?: string) {
3131
responseType: 'blob',
3232
// contentType: 'application/octet-stream;charset=UTF-8',
3333
cancelToken: source.token,
34-
}).then(res => {
35-
if (!name) {
36-
name = res.headers['content-disposition'].split(';')
37-
name = (name as any)[(name as any).length - 1].split('=')
38-
name = (name as any)[(name as any).length - 1]
39-
}
40-
const type = (name as string).split('.')
34+
})
35+
.then(res => {
36+
;(source as any).cancel = 0 // 已完成不可取消
37+
if (!name) {
38+
name = res.headers['content-disposition'].split(';')
39+
name = (name as any)[(name as any).length - 1].split('=')
40+
name = (name as any)[(name as any).length - 1]
41+
}
42+
const type = (name as string).split('.')
4143

42-
return {
43-
name,
44-
size: res.data.size,
45-
type: type[type.length - 1], // res.data.type, // application/x-msdownload
46-
src: window.URL.createObjectURL(res.data),
47-
}
48-
}) as IPromiseCancelable<IFile>
44+
return {
45+
name,
46+
size: res.data.size,
47+
type: type[type.length - 1], // res.data.type, // application/x-msdownload
48+
src: window.URL.createObjectURL(res.data),
49+
}
50+
})
51+
.catch(err => {
52+
;(source as any).cancel = 0 // 已完成不可取消
53+
throw err
54+
}) as IPromiseCancelable<IFile>
4955
promise.cancel = (message?: string) => {
5056
if (source.cancel) {
5157
console.warn(message || '取消下载:', url, query, name)

0 commit comments

Comments
 (0)