-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
49 lines (43 loc) · 1.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const path = require('path')
module.exports = (options, ctx) => {
const selector = options && options.selector ? options.selector : 'lazy'
const rootMargin = options && options.rootMargin ? options.rootMargin : '200px'
const useNative = options && typeof options.useNative === 'boolean'
? options.useNative
: options && typeof options.useLoading === 'boolean'
? options.useLoading
: true
const prefix = options && options.prefix
? options.prefix
: src => src && src.charAt(0) === '/' && !src.startsWith(ctx.base)
? ctx.base + src.slice(1)
: src
return {
name: 'vuepress-plugin-img-lazy',
chainWebpack: config => {
config.module
.rule('vue')
.test(/\.vue$/)
.use('vue-loader')
.loader('vue-loader')
.options({ transformAssetUrls: {
video: ['src', 'poster'],
source: 'src',
img: ['src', 'data-src'],
image: ['xlink:href', 'href'],
use: ['xlink:href', 'href']
}})
},
extendMarkdown: md => {
md.use(require('markdown-it-img-lazy'), { useNative, selector, prefix })
md.use(require('markdown-it-imsize'))
},
async clientDynamicModules () {
return [{
name: 'imgLazy.js',
content: `export default ${JSON.stringify({ useNative, selector, rootMargin })}`
}]
},
enhanceAppFiles: path.resolve(__dirname, 'enhanceAppFile.js')
}
}