mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:44:49 +08:00
33a2624f09
When `EMBER_CLI_PLUGIN_ASSETS=1`, plugin application JS will be compiled via Ember CLI. In this mode, the existing `register_asset` API will cause any registered JS files to be made available in `/plugins/{plugin-name}_extra.js`. These 'extra' files will be loaded immediately after the plugin app JS file, so this should not affect functionality. Plugin compilation in Ember CLI is implemented as an addon, similar to the existing 'admin' addon. We bypass the normal Ember CLI compilation process (which would add the JS to the main app bundle), and reroute the addon Broccoli tree into a separate JS file per-plugin. Previously, Sprockets would add compiled templates directly to `Ember.TEMPLATES`. Under Ember CLI, they are compiled into es6 modules. Some new logic in `discourse-boot.js` takes care of remapping the new module names into the old-style `Ember.TEMPLATES`. This change has been designed to be a like-for-like replacement of the old plugin compilation system, so we do not expect any breakage. Even so, the environment variable flag will allow us to test this in a range of environments before enabling it by default. A manual silence implementation is added for the build-time `ember-glimmer.link-to.positional-arguments` deprecation while we work on a better story for plugins.
53 lines
1.4 KiB
Ruby
53 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module EmberCli
|
|
def self.plugin_assets?
|
|
ENV["EMBER_CLI_PLUGIN_ASSETS"] == "1"
|
|
end
|
|
|
|
def self.assets
|
|
@assets ||= begin
|
|
assets = %w(
|
|
discourse.js
|
|
admin.js
|
|
wizard.js
|
|
ember_jquery.js
|
|
pretty-text-bundle.js
|
|
start-discourse.js
|
|
vendor.js
|
|
)
|
|
assets += Dir.glob("app/assets/javascripts/discourse/scripts/*.js").map { |f| File.basename(f) }
|
|
|
|
if plugin_assets?
|
|
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"
|
|
end
|
|
end
|
|
|
|
assets
|
|
end
|
|
end
|
|
|
|
def self.script_chunks
|
|
return @@chunk_infos if defined? @@chunk_infos
|
|
|
|
raw_chunk_infos = JSON.parse(File.read("#{Rails.configuration.root}/app/assets/javascripts/discourse/dist/chunks.json"))
|
|
|
|
chunk_infos = raw_chunk_infos["scripts"].map do |info|
|
|
logical_name = info["afterFile"][/\Aassets\/(.*)\.js\z/, 1]
|
|
chunks = info["scriptChunks"].map { |filename| filename[/\Aassets\/(.*)\.js\z/, 1] }
|
|
[logical_name, chunks]
|
|
end.to_h
|
|
|
|
@@chunk_infos = chunk_infos if Rails.env.production?
|
|
chunk_infos
|
|
rescue Errno::ENOENT
|
|
{}
|
|
end
|
|
|
|
def self.is_ember_cli_asset?(name)
|
|
assets.include?(name) || name.start_with?("chunk.")
|
|
end
|
|
end
|