-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathindex.js
34 lines (27 loc) · 1 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
const {
fs: { existsSync },
path: { resolve }
} = require('@vuepress/shared-utils')
const CopyPlugin = require('copy-webpack-plugin')
const mergeable = require('vuepress-mergeable')
module.exports = mergeable((patterns, context) => ({
name: `@vuepress/plugin-public-files`,
chainWebpack (config) {
if (!Array.isArray(patterns)) patterns = [patterns]
config
.plugin('copy')
.use(CopyPlugin, [patterns.map((pattern) => {
pattern = typeof pattern === 'string'
? { from: pattern }
: { ...pattern }
// `from` will be resolved based on `sourceDir`
pattern.from = resolve(context.sourceDir, pattern.from || '')
if (!existsSync(pattern.from)) return
// `to` will be resolved based on `outDir`
pattern.to = resolve(context.outDir, pattern.to || '')
// ignore dotfiles and markdown by default
pattern.ignore = pattern.ignore || ['.*', '.*/**', '*.md']
return pattern
}).filter(p => p)])
}
}), 'flat')