forked from vuejs/rollup-plugin-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (66 loc) · 2.32 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { createFilter } from 'rollup-pluginutils'
import vueTransform from './vueTransform'
import DEFAULT_OPTIONS from './options'
import compileStyle from './style/index'
import debug from './debug'
import mergeOptions from 'merge-options'
export default function vue (opts = {}) {
debug('Yo! rolling vue!')
const filter = createFilter(opts.include, opts.exclude)
delete opts.include
delete opts.exclude
/* eslint-disable */
try {
const vueVersion = require('vue').version;
if (parseInt(vueVersion.split('.')[0], 10) >= 2) {
if (!('compileTemplate' in config)) {
debug('Vue 2.0 detected. Compiling template.');
opts.compileTemplate = true;
}
} else {
if (opts.compileTemplate === true) {
console.warn('Vue version < 2.0.0 does not support compiled template.');
}
opts.compileTemplate = false;
}
} catch (e) {
}
/* eslint-enable */
const config = mergeOptions(DEFAULT_OPTIONS, opts)
const styles = {}
return {
name: 'vue',
options (opts) {
DEFAULT_OPTIONS.css = (opts.dest || 'bundle.js').replace(/js$/i, 'css')
},
resolveId (id) {
if (id.indexOf('.vue.component.') > -1) {
return id
}
},
load (id) {
if (id.indexOf('.vue.component.') < 0) return null
const component = id.replace(/\.[\d]+\.vue.component.*$/, '')
const index = parseInt(id.replace(`${component}.`, '').split('.')[0])
if (index < styles[component].length) return styles[component][index]
},
async transform (source, id) {
if (!filter(id) || !id.endsWith('.vue')) {
debug(`Ignore: ${id}`)
return null
}
debug(`Compile: ${id}`)
const { code, css, map } = await vueTransform(source, id, config)
styles[id] = css
return { code, map }
},
ongenerate () {
if (config.styleToImports !== true) {
if (config.css === undefined || config.css === null) {
config.css = DEFAULT_OPTIONS.css
}
compileStyle(styles, config)
}
}
}
}