-
Notifications
You must be signed in to change notification settings - Fork 15
/
webpack-loader.js
32 lines (28 loc) · 1005 Bytes
/
webpack-loader.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
var I18nliner = require("i18nliner").default;
var config = I18nliner.config;
var preprocess = require("./preprocess");
var hasTranslatableText = require("./hasTranslatableText")(config);
/*
* there's code in this file that dynamically requires plugins; it's
* not needed in the browser, so we skip it ... otherwise webpack
* will load *all* of i18nliner (which includes things like fs, and
* will fail).
*/
var noParsePath = "i18nliner/dist/lib/i18nliner";
var addNoParse = function() {
var escapeRegExp = require("./util/escapeRegExp");
var path = require("path");
var mod = this.options.module;
mod.noParse = mod.noParse || [];
if (!Array.isArray(mod.noParse))
mod.noParse = [mod.noParse];
mod.noParse.push(new RegExp(escapeRegExp(path.normalize(noParsePath))));
addNoParse = Function.prototype;
};
module.exports = function(source) {
this.cacheable();
addNoParse.call(this);
if (hasTranslatableText(source))
source = preprocess(source, config);
return source;
};