DEV: Allow Ember CLI assets to be used by development Rails app (#16511)
Previously, accessing the Rails app directly in development mode would give you assets from our 'legacy' Ember asset pipeline. The only way to run with Ember CLI assets was to run ember-cli as a proxy. This was quite limiting when working on things which are bypassed when using the ember-cli proxy (e.g. changes to `application.html.erb`). Also, since `ember-auto-import` introduced chunking, visiting `/theme-qunit` under Ember CLI was failing to include all necessary chunks.
This commit teaches Sprockets about our Ember CLI assets so that they can be used in development mode, and are automatically collected up under `/public/assets` during `assets:precompile`. As a bonus, this allows us to remove all the custom manifest modification from `assets:precompile`.
The key changes are:
- Introduce a shared `EmberCli.enabled?` helper
- When ember-cli is enabled, add ember-cli `/dist/assets` as the top-priority Rails asset directory
- Have ember-cli output a `chunks.json` manifest, and teach `preload_script` to read it and append the correct chunks to their associated `afterFile`
- Remove most custom ember-cli logic from the `assets:precompile` step. Instead, rely on Rails to take care of pulling the 'precompiled' assets into the `public/assets` directory. Move the 'renaming' logic to runtime, so it can be used in development mode as well.
- Remove fingerprinting from `ember-cli-build`, and allow Rails to take care of things
Long-term, we may want to replace Sprockets with the lighter-weight Propshaft. The changes made in this commit have been made with that long-term goal in mind.
tldr: when you visit the rails app directly, you'll now be served the current ember-cli assets. To keep these up-to-date make sure either `ember serve`, or `ember build --watch` is running. If you really want to load the old non-ember-cli assets, then you should start the server with `EMBER_CLI_PROD_ASSETS=0`. (the legacy asset pipeline will be removed very soon)
2022-04-21 11:26:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module EmberCli
|
2022-08-22 04:56:39 -04:00
|
|
|
def self.assets
|
|
|
|
@assets ||=
|
|
|
|
begin
|
|
|
|
assets = %w[
|
|
|
|
discourse.js
|
|
|
|
admin.js
|
|
|
|
wizard.js
|
|
|
|
ember_jquery.js
|
2022-08-29 14:11:59 -04:00
|
|
|
markdown-it-bundle.js
|
2022-08-22 04:56:39 -04:00
|
|
|
start-discourse.js
|
|
|
|
vendor.js
|
2023-01-09 07:10:19 -05:00
|
|
|
]
|
2022-08-22 04:56:39 -04:00
|
|
|
assets +=
|
|
|
|
Dir.glob("app/assets/javascripts/discourse/scripts/*.js").map { |f| File.basename(f) }
|
|
|
|
|
2022-09-21 07:38:02 -04:00
|
|
|
Discourse
|
|
|
|
.find_plugin_js_assets(include_disabled: true)
|
|
|
|
.each do |file|
|
|
|
|
next if file.ends_with?("_extra") # these are still handled by sprockets
|
|
|
|
assets << "#{file}.js"
|
2022-08-22 04:56:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
assets
|
|
|
|
end
|
|
|
|
end
|
2022-05-11 05:23:32 -04:00
|
|
|
|
DEV: Allow Ember CLI assets to be used by development Rails app (#16511)
Previously, accessing the Rails app directly in development mode would give you assets from our 'legacy' Ember asset pipeline. The only way to run with Ember CLI assets was to run ember-cli as a proxy. This was quite limiting when working on things which are bypassed when using the ember-cli proxy (e.g. changes to `application.html.erb`). Also, since `ember-auto-import` introduced chunking, visiting `/theme-qunit` under Ember CLI was failing to include all necessary chunks.
This commit teaches Sprockets about our Ember CLI assets so that they can be used in development mode, and are automatically collected up under `/public/assets` during `assets:precompile`. As a bonus, this allows us to remove all the custom manifest modification from `assets:precompile`.
The key changes are:
- Introduce a shared `EmberCli.enabled?` helper
- When ember-cli is enabled, add ember-cli `/dist/assets` as the top-priority Rails asset directory
- Have ember-cli output a `chunks.json` manifest, and teach `preload_script` to read it and append the correct chunks to their associated `afterFile`
- Remove most custom ember-cli logic from the `assets:precompile` step. Instead, rely on Rails to take care of pulling the 'precompiled' assets into the `public/assets` directory. Move the 'renaming' logic to runtime, so it can be used in development mode as well.
- Remove fingerprinting from `ember-cli-build`, and allow Rails to take care of things
Long-term, we may want to replace Sprockets with the lighter-weight Propshaft. The changes made in this commit have been made with that long-term goal in mind.
tldr: when you visit the rails app directly, you'll now be served the current ember-cli assets. To keep these up-to-date make sure either `ember serve`, or `ember build --watch` is running. If you really want to load the old non-ember-cli assets, then you should start the server with `EMBER_CLI_PROD_ASSETS=0`. (the legacy asset pipeline will be removed very soon)
2022-04-21 11:26:34 -04:00
|
|
|
def self.script_chunks
|
|
|
|
return @@chunk_infos if defined?(@@chunk_infos)
|
|
|
|
|
|
|
|
raw_chunk_infos =
|
2023-04-20 08:57:40 -04:00
|
|
|
JSON.parse(
|
|
|
|
File.read("#{Rails.configuration.root}/app/assets/javascripts/discourse/dist/chunks.json"),
|
|
|
|
)
|
DEV: Allow Ember CLI assets to be used by development Rails app (#16511)
Previously, accessing the Rails app directly in development mode would give you assets from our 'legacy' Ember asset pipeline. The only way to run with Ember CLI assets was to run ember-cli as a proxy. This was quite limiting when working on things which are bypassed when using the ember-cli proxy (e.g. changes to `application.html.erb`). Also, since `ember-auto-import` introduced chunking, visiting `/theme-qunit` under Ember CLI was failing to include all necessary chunks.
This commit teaches Sprockets about our Ember CLI assets so that they can be used in development mode, and are automatically collected up under `/public/assets` during `assets:precompile`. As a bonus, this allows us to remove all the custom manifest modification from `assets:precompile`.
The key changes are:
- Introduce a shared `EmberCli.enabled?` helper
- When ember-cli is enabled, add ember-cli `/dist/assets` as the top-priority Rails asset directory
- Have ember-cli output a `chunks.json` manifest, and teach `preload_script` to read it and append the correct chunks to their associated `afterFile`
- Remove most custom ember-cli logic from the `assets:precompile` step. Instead, rely on Rails to take care of pulling the 'precompiled' assets into the `public/assets` directory. Move the 'renaming' logic to runtime, so it can be used in development mode as well.
- Remove fingerprinting from `ember-cli-build`, and allow Rails to take care of things
Long-term, we may want to replace Sprockets with the lighter-weight Propshaft. The changes made in this commit have been made with that long-term goal in mind.
tldr: when you visit the rails app directly, you'll now be served the current ember-cli assets. To keep these up-to-date make sure either `ember serve`, or `ember build --watch` is running. If you really want to load the old non-ember-cli assets, then you should start the server with `EMBER_CLI_PROD_ASSETS=0`. (the legacy asset pipeline will be removed very soon)
2022-04-21 11:26:34 -04:00
|
|
|
|
|
|
|
chunk_infos =
|
|
|
|
raw_chunk_infos["scripts"]
|
|
|
|
.map do |info|
|
|
|
|
logical_name = info["afterFile"][%r{\Aassets/(.*)\.js\z}, 1]
|
|
|
|
chunks = info["scriptChunks"].map { |filename| filename[%r{\Aassets/(.*)\.js\z}, 1] }
|
|
|
|
[logical_name, chunks]
|
|
|
|
end
|
|
|
|
.to_h
|
|
|
|
|
|
|
|
@@chunk_infos = chunk_infos if Rails.env.production?
|
|
|
|
chunk_infos
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
2022-05-11 05:23:32 -04:00
|
|
|
def self.is_ember_cli_asset?(name)
|
2022-08-22 04:56:39 -04:00
|
|
|
assets.include?(name) || name.start_with?("chunk.")
|
2022-05-11 05:23:32 -04:00
|
|
|
end
|
2022-08-30 11:27:14 -04:00
|
|
|
|
|
|
|
def self.ember_version
|
|
|
|
@version ||=
|
|
|
|
begin
|
2023-04-20 08:57:40 -04:00
|
|
|
ember_source_package_raw =
|
|
|
|
File.read("#{Rails.root}/app/assets/javascripts/node_modules/ember-source/package.json")
|
2022-08-30 11:27:14 -04:00
|
|
|
JSON.parse(ember_source_package_raw)["version"]
|
|
|
|
end
|
|
|
|
end
|
DEV: Allow Ember CLI assets to be used by development Rails app (#16511)
Previously, accessing the Rails app directly in development mode would give you assets from our 'legacy' Ember asset pipeline. The only way to run with Ember CLI assets was to run ember-cli as a proxy. This was quite limiting when working on things which are bypassed when using the ember-cli proxy (e.g. changes to `application.html.erb`). Also, since `ember-auto-import` introduced chunking, visiting `/theme-qunit` under Ember CLI was failing to include all necessary chunks.
This commit teaches Sprockets about our Ember CLI assets so that they can be used in development mode, and are automatically collected up under `/public/assets` during `assets:precompile`. As a bonus, this allows us to remove all the custom manifest modification from `assets:precompile`.
The key changes are:
- Introduce a shared `EmberCli.enabled?` helper
- When ember-cli is enabled, add ember-cli `/dist/assets` as the top-priority Rails asset directory
- Have ember-cli output a `chunks.json` manifest, and teach `preload_script` to read it and append the correct chunks to their associated `afterFile`
- Remove most custom ember-cli logic from the `assets:precompile` step. Instead, rely on Rails to take care of pulling the 'precompiled' assets into the `public/assets` directory. Move the 'renaming' logic to runtime, so it can be used in development mode as well.
- Remove fingerprinting from `ember-cli-build`, and allow Rails to take care of things
Long-term, we may want to replace Sprockets with the lighter-weight Propshaft. The changes made in this commit have been made with that long-term goal in mind.
tldr: when you visit the rails app directly, you'll now be served the current ember-cli assets. To keep these up-to-date make sure either `ember serve`, or `ember build --watch` is running. If you really want to load the old non-ember-cli assets, then you should start the server with `EMBER_CLI_PROD_ASSETS=0`. (the legacy asset pipeline will be removed very soon)
2022-04-21 11:26:34 -04:00
|
|
|
end
|