0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 01:10:43 +08:00
discourse/lib/freedom_patches/propshaft_patches.rb
David Taylor 9527868295
DEV: Replace JS build system with Rolldown (#35963)
This replaces the old ember-cli build with a modern Rolldown build. In
local testing, this provides an 80% improvement in build times, while
remaining 100% backwards compatible for themes and plugins.

As part of this move, we have decided to stop using a proxy in front of
Discourse for development. Development should now be done directly
against the Rails server.

`bin/ember-cli -u` has been replaced with `bin/dev`. This will launch
Rails on `:3000`, and will run the rolldown build in the background. Log
output from both processes will be shown with an appropriate prefix. You
should visit `:3000` in your browser. `:4200` will no longer serve
anything.

To help with migration, `bin/ember-cli` is now a backwards-compatible
shim. It will print help information, and will launch a lightweight
server on `:4200` with instructions to move to `:3000`.

If you prefer to launch Rails and the JS build as separate commands, you
can still do that. Rails boot commands are unchanged, and the rolldown
development builder can be run using `bin/dev --only ember`.

https://meta.discourse.org/t/403908

---------

Co-authored-by: Jarek Radosz <jarek@cvx.dev>
Co-authored-by: Chris Manson <chris@manson.ie>
2026-05-29 11:11:55 +01:00

44 lines
1.2 KiB
Ruby
Vendored

# frozen_string_literal: true
Propshaft::Helper.prepend(
Module.new do
def compute_asset_path(path, options = {})
attempts = 0
begin
super
rescue Propshaft::MissingAssetError => e
if Rails.env.test?
# Assets might not be compiled in test mode. Just return a fake path
"/assets/#{path}"
elsif Rails.env.development?
# Ember-cli might've replaced the assets
Rails.application.assets.load_path.send(:clear_cache)
attempts += 1
retry if attempts < 3
raise e
else
raise e
end
end
end
end,
)
Propshaft::Compiler::SourceMappingUrls.prepend(
Module.new do
def compile(asset, input)
if asset.logical_path.to_s.include?(".digested.")
input
else
super
end
end
def source_mapping_url(*args)
# Propshaft insists on converting sourcemap URLs to absolute paths. We want to keep
# relative paths so that we can serve assets from different subdirectories without needing
# to recompile them
super.gsub(%r{sourceMappingURL=\S+/([^/]+\.map)}, 'sourceMappingURL=\1')
end
end,
)