-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (65 loc) · 2 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
/**
* @file 入口模块
* @author sparklewhy@gmail.com
*/
var vueCompilerCore = require('vue-compiler-core');
var insertCssLibDir = null;
function getInsertCssLibDir() {
if (insertCssLibDir != null) {
return insertCssLibDir;
}
var pkgName = require('./package.json').name;
var path = require('path');
var corePath = path.join(__dirname, 'node_modules', 'vue-compiler-core');
var result;
try {
require.resolve(corePath);
result = path.join(pkgName, 'node_modules');
}
catch (ex) {
result = '';
}
insertCssLibDir = result;
return result;
}
var hotReloadApiDir = null;
function getHotReloadApiDir() {
if (hotReloadApiDir != null) {
return hotReloadApiDir;
}
var pkgName = require('./package.json').name;
var path = require('path');
var hotReloadApiPkg = 'vue-hot-reload-api';
var corePath = path.join(__dirname, 'node_modules', hotReloadApiPkg);
var result;
try {
require.resolve(corePath);
result = path.join(pkgName, 'node_modules', hotReloadApiPkg);
}
catch (ex) {
result = hotReloadApiPkg;
}
hotReloadApiDir = result;
return result;
}
module.exports = exports = {
compiler: vueCompilerCore.compiler,
compile: function (filePath, content, options) {
var assign = require('object-assign');
var opts = assign({}, options, {
insertCssLibDir: getInsertCssLibDir(),
hotReloadApiDir: getHotReloadApiDir()
});
if (!opts.template) {
opts.template = {};
}
if (opts.template.compileToRender !== false) {
opts.template.compileToRender = require('./lib/template-compiler');
}
var parser = require('./lib/parser');
var parts = vueCompilerCore.parse(filePath, content, parser);
return vueCompilerCore.compile(parts, opts);
},
registerFisParser: vueCompilerCore.registerFisParser,
registerParser: vueCompilerCore.registerParser
};