-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
20 lines (20 loc) · 770 Bytes
/
index.js
File metadata and controls
20 lines (20 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict';
const path = require('path');
const loaderUtils = require('loader-utils');
const node = require('./lib/node');
const web = require('./lib/web');
module.exports = function(source) {
this.cacheable();
const options = loaderUtils.getOptions(this) || {};
const config = { codeSegment: '' };
if (options.templateFile) {
// fix windows path error
const templateFilePath = path.resolve(this.rootContext, options.templateFile);
const nomarlizeTemplateFilePath = templateFilePath.replace(/\\/g, '\\\\');
config.codeSegment = `import codeSegment from '${nomarlizeTemplateFilePath}'
codeSegment(Vue);`;
}
const loader = this.target === 'node' ? node : web;
const content = loader(this, source, options, config);
return content;
};