Skip to content

Commit

Permalink
Sideloading module loader to avoid scoping issues
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneZ committed Nov 24, 2016
1 parent f51d5bb commit fb7ea01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 11 additions & 1 deletion src/browserify-plugin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand All @@ -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
11 changes: 1 addition & 10 deletions src/reloading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fb7ea01

Please sign in to comment.