-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathindex.js
31 lines (26 loc) · 949 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
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (content) {
if (this.version && this.version >= 2) {
try {
this.cacheable && this.cacheable();
this.callback(null, 'module.exports = ' + generateCode(content));
} catch (err) {
this.emitError(err.message);
this.callback(err);
}
} else {
var message = 'support webpack 2 later';
this.emitError(message);
this.callback(new Error(message));
}
};
function generateCode(content) {
var code = '';
var value = typeof content === 'string' ? JSON.parse(content) : content;
value = JSON.stringify(value).replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029').replace(/\\/g, '\\\\');
code += 'function (Component) {\n Component.options.__i18n = Component.options.__i18n || []\n Component.options.__i18n.push(\'' + value.replace(/\u0027/g, '\\u0027') + '\')\n}\n';
return code;
}