-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (35 loc) · 977 Bytes
/
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
'use strict';
var textr = require('textr');
var loaderUtils = require('loader-utils');
module.exports = function textrLoader(content, map) {
// Signal to webpack this is cacheable
this.cacheable();
/**
* Get plugins list from options.
* This is expected to be an array of the form:
*
* textr: [
* require('typographic-ellipses'),
* require('typographic-single-spaces'),
* require('typographic-quotes')
* ]
*/
let plugins = this.options.textr;
if(typeof plugins === 'undefined') {
plugins = [];
}
/**
* Get any options from the query string.
* For example, `textr?locale=en-us`
*/
var query = loaderUtils.parseQuery(this.query);
// Create textr instance with query opts
let tf = textr(query);
// Apply each plugin using `.use`
plugins.forEach((plugin) => {
console.log('applying plugin', plugin);
tf.use(plugin)
})
var callback = this.async();
return callback(null, tf(content));
}