Use local npm modules for utility sub-modules

This commit is contained in:
SleepWalker
2016-07-23 00:21:04 +03:00
parent fc84fb49c6
commit 003a224688
6 changed files with 8 additions and 6 deletions

View File

@ -0,0 +1,21 @@
module.exports = function() {
this.cacheable && this.cacheable();
var moduleId = this.context
.replace(this.options.resolve.root, '')
.replace(/^\/|\/$/g, '')
.replace(/\//g, '.');
var content = this.inputValue[0];
content = JSON.stringify(Object.keys(content).reduce(function(translations, key) {
translations[key] = {
id: moduleId + '.' + key,
defaultMessage: content[key]
};
return translations;
}, {}));
return 'import { defineMessages } from \'react-intl\';'
+ 'export default defineMessages(' + content + ')';
};