Skip to content

Commit

Permalink
Hotify module.exports own properties
Browse files Browse the repository at this point in the history
This is useful for ES6-style exports (.default), multiple component exports and some other use cases (e.g. OmniscientJS exporting `module.exports.jsx`).
  • Loading branch information
gaearon committed Dec 22, 2014
1 parent 48e3ec8 commit 5e57a4b
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,26 @@ module.exports = function (source, map) {
appendText = [
'/* REACT HOT LOADER */',
'if (module.hot) {',
acceptUpdates ? [
'module.hot.accept(function (err) {',
'if (err) {',
'console.error("Cannot not apply hot update to " + ' + JSON.stringify(filename) + ' + ": " + err.message);',
'(function () {',
acceptUpdates ? [
'module.hot.accept(function (err) {',
'if (err) {',
'console.error("Cannot not apply hot update to " + ' + JSON.stringify(filename) + ' + ": " + err.message);',
'}',
'});'
].join(' ') : '',
'module.hot.dispose(function (data) {',
' data.makeHot = module.makeHot;',
'});',
'if (module.exports && module.makeHot) {',
'module.exports = module.makeHot(module.exports, "__MODULE_EXPORTS");',
'for (var key in module.exports) {',
'if (module.exports[key] && module.exports.hasOwnProperty(key)) {',
'module.exports[key] = module.makeHot(module.exports[key], "__MODULE_EXPORTS_" + key);',
'}',
'}',
'});'
].join(' ') : '',
'module.hot.dispose(function (data) {',
' data.makeHot = module.makeHot;',
'});',
'if (module.exports && module.makeHot) {',
' module.exports = module.makeHot(module.exports, "__MODULE_EXPORTS")',
'}',
'}',
'})();',
'}'
].join(' ');

Expand Down

0 comments on commit 5e57a4b

Please sign in to comment.