Skip to content

inline sourceContent #1

Closed
Closed

Description

@ForbesLindesay

for the browserify source map example (https://github.com/thlorenz/browserify-sourcemap-example/blob/master/routes/bundle.js#L16) you have to know where the original code will be hosted (and that it will be hosted). It would be useful if inline-source-map supported the sourcesContent field (assuming it still exists). The only decent refrence I could find to it was in https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#

Including that would allow you to inline the original scripts, which would lead to a very long sourceURL, but would be much simpler from a user perspective. Since this should only really be used for debugging, I don't think it's an issue if the sourceURLs get really long.

Activity

  1. thlorenz commented on Mar 11, 2013

    @thlorenz
    Owner

    Great idea!

    Dug into chrome tools source (canary) and found:

    if (map.sourcesContent && map.sourcesContent[i])
     this._sourceContentByURL[url] = map.sourcesContent[i];
    }

    So it looks indeed like it's still supported. Unfortunately the underlying source-map I'm using doesn't support it, so I have to do some tinkering.

    I definitely agree however that his would simplify things for the user immensely and since this is for development only I wouldn't be too concerned about file-size (you would just not include sourcemaps in production).

    If you want to debug production code however it makes sense to not include the sourceFiles only and load the actual sources via sourceRoot from any given url. Looks like I need to allow different options here.

  2. thlorenz commented on Mar 11, 2013

    @thlorenz
    Owner

    Added in version 0.2.

    I also updated the browser-pack and browserify forks and the sample app.

    If you launch the sample app and watch the logs, you'll see that it no longer loads the sources, since it already has them inlined in the source map.

    Actually just realized, inlined sourcemaps are not used properly, however using a file://full/path/to/original.js source file solves this issue as well, since it now loads the files from the disk directly (no relative path to bundle necessary).
    Will figure out tonight how to make inlined content work ;).

  3. thlorenz commented on Mar 11, 2013

    @thlorenz
    Owner

    Actually I found the bug (it is sourcesContent - I had sourceContent).
    At this point I can generate the bundle, delete all originals and still see/debug original code.

    i.e. try the example in my browserify fork.

    Do a node build.js. Then rm js/foo.js && rm js/main.js.
    open index.html, open dev tools (may have to refresh twice for the mapped files to show).

    Although the files no longer exist, their content is shown.

  4. ForbesLindesay commented on Mar 11, 2013

    @ForbesLindesay
    Author

    Excellent. A nice demo might be to just not serve up the original source files.

  5. thlorenz commented on Mar 11, 2013

    @thlorenz
    Owner

    Good idea, I removed the static server from the example, however this doesn't prove much, since I am using file:// as the source root which enables chrome to load it without a server even if the source wasn't included.

    The browserify sample I mentioned above is a better proof since it allows you to generate the bundle, then delete the original files and confirm that you can still see the original sources.

  6. ForbesLindesay commented on Mar 11, 2013

    @ForbesLindesay
    Author

    I'm super excited to see this stuff in the core of browserify. At that point I'll be ready to build a little middlware library and begin switching all my projects over from component to browserify.

  7. thlorenz commented on Mar 11, 2013

    @thlorenz
    Owner

    Nice!

    I'll get this into a state where it can be merged in at least with just the debug option which for now will always inline the sources.

    We should think about some advanced browserify options as well @substack, i.e.:

    • don't inline when desired to allow people to use sourcemaps in production (point sourceRoot to dev server)
    • set sourceRoot so files in sources appear as js/foo.js instead of /User/../../public/js/foo.js (in this case setting sourceRoot to /User/../../public would do the trick
  8. thlorenz commented on Mar 12, 2013

    @thlorenz
    Owner

    Ok, the main functionality is in.

    Until @substack pulls this, you could use my fork @ForbesLindesay to play with it.

  9. ForbesLindesay commented on Mar 12, 2013

    @ForbesLindesay
    Author

    Cool, looks like it's merged already. Very excited to start using it 😄

    I think this issue is now fully resolved. I guess you might want to open a separate issue to get optional support for source maps in production too. I think they'll be quite a big additional challenge with that though as you'll need to also support pass through with uglify-js etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions