diff --git a/src/browserify-plugin/main.js b/src/browserify-plugin/main.js index f986a39..a78a931 100644 --- a/src/browserify-plugin/main.js +++ b/src/browserify-plugin/main.js @@ -153,7 +153,8 @@ function LiveReactloadPlugin(b, opts = {}) { clientOpts ] let bundleSrc = - `(${loader.toString()})(${args.map(a => JSON.stringify(a, null, 2)).join(", ")});` + `(${loader.toString()})(${args.map(a => JSON.stringify(a, null, 2)).join(", ")}); + ${__livereactload_loadAsModule.toString()};` if (standalone) { bundleSrc = umd(standalone, `return ${bundleSrc}`) } @@ -172,4 +173,13 @@ function LiveReactloadPlugin(b, opts = {}) { } } +function __livereactload_loadAsModule(__livereactload_source, __livereactload_sourcemap) { + return eval( + 'function __livereactload_module(require, module, exports){\n' + + __livereactload_source + + '\n}; __livereactload_module;' + + (__livereactload_sourcemap || '') + ); +} + module.exports = LiveReactloadPlugin diff --git a/src/reloading.js b/src/reloading.js index aa262ae..b501c91 100644 --- a/src/reloading.js +++ b/src/reloading.js @@ -84,7 +84,7 @@ function loader(mappings, entryPoints, options) { var body = mapping[0]; if (typeof body !== "function") { debug("Compiling module", mapping[2]) - var compiled = loadAsModule(body, mapping[2].sourcemap); + var compiled = __livereactload_loadAsModule(body, mapping[2].sourcemap); mapping[0] = compiled; mapping[2].source = body; } @@ -429,15 +429,6 @@ function loader(mappings, entryPoints, options) { console.error("LiveReactload ::", msg); } - function loadAsModule(__livereactload_source, __livereactload_sourcemap) { - return eval( - 'function __livereactload_module(require, module, exports){\n' + - __livereactload_source + - '\n}; __livereactload_module;' + - (__livereactload_sourcemap || '') - ); - } - } module.exports = loader;