-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
38 lines (35 loc) · 1.33 KB
/
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
var loaderUtils = require('loader-utils')
module.exports = function () {}
module.exports.pitch = function (remainingRequest) {
if (typeof this.cacheable === 'function') {
this.cacheable()
}
var query = loaderUtils.parseQuery(this.query)
var locale = query.locale
var req = loaderUtils.stringifyRequest(this, '!!' + remainingRequest)
return [
'var addLocaleData = require("react-intl").addLocaleData;',
'var isIntlLocaleSupported = require("intl-locales-supported");',
'module.exports = function (cb) {',
' if (isIntlLocaleSupported("' + locale + '")) {',
' require.ensure([',
' "react-intl/locale-data/' + locale + '",',
' ' + req,
' ], function (require) {',
' addLocaleData(require("react-intl/locale-data/' + locale + '"));',
' cb(require(' + req + '));',
' }, "locale-' + locale + '-no-intl");',
' } else {',
' require.ensure([',
' "intl/locale-data/jsonp/' + locale + '",',
' "react-intl/locale-data/' + locale + '",',
' ' + req,
' ], function (require) {',
' require("intl/locale-data/jsonp/' + locale + '");',
' addLocaleData(require("react-intl/locale-data/' + locale + '"));',
' cb(require(' + req + '));',
' }, "locale-' + locale + '");',
' }',
'};'
].join('\n')
}