Skip to content

Commit

Permalink
Perf: 细节
Browse files Browse the repository at this point in the history
  • Loading branch information
Maorey committed Apr 20, 2020
1 parent 7792610 commit f872023
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
6 changes: 5 additions & 1 deletion build/development.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ module.exports = function(config) {
// },
// ])
// 补全html插入资源
config.plugin('insert-preload').use(require.resolve('./insertPreload.js'))
config
.plugin('insert-preload')
.use(require.resolve('./insertPreload.js'), [
{ noPreload: true, noPrefetch: true },
])
// stylelint
config.plugin('stylelint').use('stylelint-webpack-plugin', [
{
Expand Down
34 changes: 20 additions & 14 deletions src/utils/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ function download(url: string, query?: IObject, name?: string) {
responseType: 'blob',
// contentType: 'application/octet-stream;charset=UTF-8',
cancelToken: source.token,
}).then(res => {
if (!name) {
name = res.headers['content-disposition'].split(';')
name = (name as any)[(name as any).length - 1].split('=')
name = (name as any)[(name as any).length - 1]
}
const type = (name as string).split('.')
})
.then(res => {
;(source as any).cancel = 0 // 已完成不可取消
if (!name) {
name = res.headers['content-disposition'].split(';')
name = (name as any)[(name as any).length - 1].split('=')
name = (name as any)[(name as any).length - 1]
}
const type = (name as string).split('.')

return {
name,
size: res.data.size,
type: type[type.length - 1], // res.data.type, // application/x-msdownload
src: window.URL.createObjectURL(res.data),
}
}) as IPromiseCancelable<IFile>
return {
name,
size: res.data.size,
type: type[type.length - 1], // res.data.type, // application/x-msdownload
src: window.URL.createObjectURL(res.data),
}
})
.catch(err => {
;(source as any).cancel = 0 // 已完成不可取消
throw err
}) as IPromiseCancelable<IFile>
promise.cancel = (message?: string) => {
if (source.cancel) {
console.warn(message || '取消下载:', url, query, name)
Expand Down

0 comments on commit f872023

Please sign in to comment.