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

Path is missing from source maps #8

Closed
schlaup opened this issue Feb 18, 2015 · 2 comments
Closed

Path is missing from source maps #8

schlaup opened this issue Feb 18, 2015 · 2 comments

Comments

@schlaup
Copy link

schlaup commented Feb 18, 2015

I tried your loader in a test project and found out that the path is missing from the source maps.

For example:

  • App
    • Component
      • Page.jsx
      • Helper.ts

end up in Chrome as:

  • App
    • Component
      • Page.jsx
  • Helper.ts

I compared your loader with the jsx-loader and saw that the jsx-loader sets two additional properties on the sourcemap. (sources and files)

I changed your code and it works now: (basically a copy from jsx-loader)

...

    if (options.sourceMap) {
        var sourceFilename = loaderUtils.getRemainingRequest(this);
        var current = loaderUtils.getCurrentRequest(this);
        sourceMap = JSON.parse(output.outputFiles[0].text);
        sourceMap.sources = [sourceFilename];
        sourceMap.file = current;
        sourceMap.sourcesContent = [contents];
        contents = output.outputFiles[1].text;
    }

...

Does this look ok to you?

Could you incorporate this change in your code and npm module?

Thanks!

@jbrantly
Copy link
Member

Hey thanks for doing all of the hard work on this! Sorry for the delay in implementing it. This is published in v0.3.2.

@schlaup
Copy link
Author

schlaup commented Feb 24, 2015

Ok, thanks, I just discovered an additional problem:

Typescript places its own "//# sourceMappingURL=SomeFile.ts" in the JavaScript output.

So the bundle.js files ends up with multiple "# sourceMappingURL" declarations. (Of course, only the last "# sourceMappingURL=bundle.js.map" is valid)

It seems that Chrome does not care, but other tools do. (For example "NPM source-map-support")

The solution is to remove the redundant and incorrect "sourceMappingURL" declaration.

I added another line:

if (options.sourceMap) {
    var sourceFilename = loaderUtils.getRemainingRequest(this);
    var current = loaderUtils.getCurrentRequest(this);
    sourceMap = JSON.parse(output.outputFiles[0].text);
    sourceMap.sources = [sourceFilename];
    sourceMap.file = current;
    sourceMap.sourcesContent = [contents];
    contents = output.outputFiles[1].text;

This line here:

    contents = contents.replace("# sourceMappingURL=", " ");
}

This solves the problem.

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