-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (33 loc) · 1.2 KB
/
index.js
File metadata and controls
40 lines (33 loc) · 1.2 KB
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
var loaderUtils = require('loader-utils'),
_ = require('lodash'),
path = require('path'),
fs = require('fs'),
helper = require('./src/helper');
var defaultOptions = {
test: /\.vue\./,
types: {
template: '\\.html$|\\.pug$|\\.jade$',
script: '\\.jsx?$|\\.coffee$|\\.tsx?$',
style: '\\.css$|\\.s(a|c)ss$|\\.styl$|\\.less$'
}
};
module.exports = function (content, map) {
map = map || {};
var loaderOptions = loaderUtils.getOptions(this);
var inputFile = map.file || path.basename(this.resourcePath),
options = _.assign({}, _.cloneDeep(defaultOptions), loaderOptions),
dirPath = this.context,
fileNames = fs.readdirSync(dirPath).filter(function (file) {
return !file.match(/^\./);
});
_.forEach(defaultOptions.types, function (definition, type) {
var defaultDefinition = definition.split(/\|(?=\\)/g);
var loaderDefinition = _.get(loaderOptions, 'types[' + type + ']', '').split(/\|(?=\\)/g);
options.types[type] = _.compact(defaultDefinition.concat(loaderDefinition)).join('|');
});
if (fileNames.length === 0) {
return;
}
var parts = helper.createParts(options, dirPath, inputFile, fileNames);
return helper.createTags(parts).join('');
};