-
Notifications
You must be signed in to change notification settings - Fork 101
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
Make Propshaft compatible with esbuild's --public-path
option
#150
Make Propshaft compatible with esbuild's --public-path
option
#150
Conversation
I'm not sure I understand the change. The |
ed772e8
to
dd32663
Compare
These may be outputted by esbuild when using its `--public-path` option
The issue isn't in the regex per se, but the I broke my commit into two, so that you could see that sourcemap output which esbuild emits ( |
@brenogazzola 👋 Would it be helpful if I created a fresh Rails repo to demonstrate the problem this is fixing? |
It would yes. Or at least reproduction steps. This way it's easier for me to compare things and figure out if there's anything else that needs to change 🙏 |
Okay! I created a repo here: https://github.com/gjtorikian/propshaft-esbuild-error Open up package.json and you'll notice that we are transpiling TS into JS, and the command to generate the final JS is:
Run If you pop open the dev console, you'll see this: That's incorrect, because the source maps aren't being included. In the Gemfile, introduce my fork and run
Run the server again, open the dev console, and you should see: The source map is correctly included. I started from a fresh Let me know if you need more info! |
You know, now I'm even wondering...do I even need jsbundling-rails here? The propshaft README offers:
I always thought jsbundling-rails was just a Ruby way to call an npm task, but is it possibly interfering here? |
Bumping this. #133 introduced a conflict that doesn’t affect this original issue. |
…ap-with-esbuild-public-path
@brenogazzola gentle bump. I fixed the previous merge conflict. Even a confirmation that I am doing something wrong with my propshaft setup would be useful. |
Ops, sorry about the delay. I'm still trying to figure out if this is a config error or a bug in propshaft. Debugging your project, the problem seems to be the final option you added: If you remove it, it will work. Propshaft indexes the source map as I thought that was it, but after precompiling its broken again. So I need a bit more time to see if I can find a config that makes both work. |
Thank you for the reply, but in the OP I mentioned:
I'm really trying to figure out what the right thing to do is here. |
For anyone encountering this issue with esbuild and propshaft, you can monkey patch the compile with the regex in this PR: # config/initializers/propshaft_sourcemappingurl_patch.rb
class Propshaft::Compiler::SourceMappingUrls
PREFIXED_SOURCE_MAPPING_PATTERN = %r{(//|/\*)# sourceMappingURL=(?:.*/)?(.*\.map)(\s*?\*/)?\s*?\Z}
def compile(logical_path, input)
input.gsub(PREFIXED_SOURCE_MAPPING_PATTERN) do
source_mapping_url(
asset_path(::Regexp.last_match(2), logical_path),
::Regexp.last_match(1),
::Regexp.last_match(3)
)
end
end
end |
Merged #170 as that seemed the more correct solution since it removes the |
esbuild has a config option,
--public-path
, which is necessary to use for integration withjsbundling-rails
; this comment explains why it's desirable to have.Unfortunately, when combining this option with source map generation, Propshaft (and Sprockets, too) is unable to read the sourcemap location, because it doesn't recognize a prefixed directory path. This PR, which was adapted wholly from
rails/sprockets-rails#515, fixes the issue, and enables esbuild users who need source map generation to integrate with Propshaft.