-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
53 lines (46 loc) · 1.48 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
const compiler = require("vue-template-compiler");
const { compileTemplate } = require("@vue/component-compiler-utils");
const loaderUtils = require("loader-utils");
module.exports = function(source, map) {
const options = loaderUtils.getOptions(this) || {};
const isProduction =
options.productionMode ||
this.minimize ||
process.env.NODE_ENV === "production";
const isServer = this.target === "node";
const query = loaderUtils.parseQuery(this.resourceQuery);
const slotName = query.name || "default";
// for vue-component-compiler
const compilerOptions = {
source,
filename: this.resourcePath,
compiler,
compilerOptions: {
outputSourceRange: true
},
// allow customizing behavior of vue-template-es2015-compiler
transpileOptions: options.transpileOptions,
transformAssetUrls: options.transformAssetUrls || true,
isProduction,
isFunctional: false,
optimizeSSR: isServer && options.optimizeSSR !== false,
prettify: options.prettify
};
const compiled = compileTemplate(compilerOptions);
const condition = query["v-if"]
? `(() => {
return ${query["v-if"]}
})()`
: "true";
this.callback(
null,
`import bind from 'vue-slot-loader/bindSlot.js'
export default function (Component) {
${compiled.code}
bind(Component, function () {
return ${condition} ? render.call(this) : null
}, ${JSON.stringify(slotName)})
}`,
map
);
};