-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathindex.js
executable file
·44 lines (36 loc) · 1.05 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
const fs = require('fs-extra')
const path = require('path')
module.exports = function nuxtVendor (moduleOptions) {
if (Array.isArray(moduleOptions)) {
moduleOptions = {
vendor: moduleOptions
}
}
const vendorDir = path.resolve(this.options.srcDir, 'static', 'vendor')
const modulesDir = Array.isArray(this.options.modulesDir) ? this.options.modulesDir : [this.options.modulesDir]
const vendor = [].concat(this.options.vendor, moduleOptions.vendor)
.filter(v => v)
.map(v => {
for (let dir of modulesDir) {
const src = path.resolve(dir, v.src || v)
if (fs.existsSync(src)) {
return {
src,
dst: v.dst || path.resolve(vendorDir, v)
}
}
}
})
.filter(v => v)
if (!vendor.length) {
return
}
// Ensure static/vendor directory exists
fs.ensureDirSync(vendorDir)
// Link vendors
vendor.forEach(({ src, dst }) => {
fs.removeSync(dst)
fs.ensureSymlinkSync(src, dst, 'junction')
})
}
module.exports.meta = require('./package.json')