Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source maps break #17

Closed
jnicholl opened this issue Aug 25, 2016 · 2 comments
Closed

Source maps break #17

jnicholl opened this issue Aug 25, 2016 · 2 comments

Comments

@jnicholl
Copy link

jnicholl commented Aug 25, 2016

So far working with inject-loader has been great, but I found that source maps don't produce the right line numbers for injected modules. I'm running ES6 code through babel and using inject-loader to mock out dependencies for testing.
I was able to get something working by joining lines with spaces instead of \n and just passing the provided source map (second argument) back in this.callback. This isn't really right - the source map really needs a transform applied?

module.exports = function inject(src, sourceMap) {
  this.cacheable && this.cacheable();
  var regex = createRequireStringRegex(loaderUtils.parseQuery(this.query));

  var lines = [
    'module.exports = function inject(injections) {',
    'var module = {exports: {}};',
    'var exports = module.exports;',
    src.replace(regex, "(injections[$1] || $&)"),
    'return module.exports;',
    '}'
  ];

  if (sourceMap) {
    this.callback(null, lines.join(" "), sourceMap);
  } else {
    return lines.join("\n");
  }
}
@plasticine
Copy link
Owner

Hey @jnicholl Thanks for the report. This is the same issue as #10, so if you don’t mind I’ll close this in favour of that earlier issue.

@jnicholl
Copy link
Author

jnicholl commented Sep 6, 2016

Works for me. Sorry, I read through that issue but didn't quite realize it was the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants