Skip to content

Commit

Permalink
Fixes #127
Browse files Browse the repository at this point in the history
Sourcemap issues fixed
  • Loading branch information
EugeneZ committed Nov 24, 2016
1 parent c5d6935 commit 759fde8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
},
"dependencies": {
"cli-color": "1.1.0",
"convert-source-map": "1.3.0",
"lodash": "4.13.1",
"md5": "2.1.0",
"offset-sourcemap-lines": "1.0.0",
"through2": "2.0.1",
"umd": "3.0.1",
"ws": "1.1.1"
Expand Down
14 changes: 13 additions & 1 deletion src/browserify-plugin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import through from "through2"
import md5 from "md5"
import {readFileSync} from "fs"
import {resolve} from "path"
import convertSourceMaps from 'convert-source-map'
import offsetSourceMaps from 'offset-sourcemap-lines'
import {startServer} from "./server"
import {log} from "./console"
import loader from "../reloading"
Expand Down Expand Up @@ -96,10 +98,20 @@ function LiveReactloadPlugin(b, opts = {}) {
b.pipeline.get("label").push(through.obj(
function transform(row, enc, next) {
const {id, file, source, deps, entry} = row
const converter = convertSourceMaps.fromSource(source)
let sourceWithoutMaps = source
let adjustedSourcemap = ''

if (converter) {
converter.setProperty('sources', [file])
sourceWithoutMaps = convertSourceMaps.removeComments(source)
adjustedSourcemap = convertSourceMaps.fromObject(offsetSourceMaps(converter.toObject(), 1)).toComment()
}

if (entry) {
entries.push(file)
}
mappings[file] = [source, deps, {id: file, hash: md5(source), browserifyId: id}]
mappings[file] = [sourceWithoutMaps, deps, {id: file, hash: md5(sourceWithoutMaps), browserifyId: id, sourcemap: adjustedSourcemap}]
next(null, row)
},
function flush(next) {
Expand Down
13 changes: 11 additions & 2 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 = new Function("require", "module", "exports", body);
var compiled = loadAsModule(body, mapping[2].sourcemap);
mapping[0] = compiled;
mapping[2].source = body;
}
Expand Down Expand Up @@ -428,8 +428,17 @@ function loader(mappings, entryPoints, options) {
function error(msg) {
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;
module.exports["default"] = loader;
Expand Down

0 comments on commit 759fde8

Please sign in to comment.