mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: Plugin support for transpiling regular .js
files (#9398)
This adds support for a new piece of metadata to your plugin.rb files. If you add: ``` transpile_js: true ``` Then Discourse will support transpilation of assets in your `assets/javascripts` directory. Previously they had to be named `.js.es6` but now regular `.js` will work. Note this is opt-in because some plugins currently have `.js` files in app/assets that are not meant to be transpiled. Going forward all plugins should migrate to this setting as they are comfortable able to do so.
This commit is contained in:
@ -4,6 +4,10 @@ require 'mini_racer'
|
||||
|
||||
class DiscourseJsProcessor
|
||||
|
||||
def self.plugin_transpile_paths
|
||||
@@plugin_transpile_paths ||= Set.new
|
||||
end
|
||||
|
||||
def self.call(input)
|
||||
root_path = input[:load_path] || ''
|
||||
logical_path = (input[:filename] || '').sub(root_path, '').gsub(/\.(js|es6).*$/, '').sub(/^\//, '')
|
||||
@ -56,6 +60,8 @@ class DiscourseJsProcessor
|
||||
embed-application
|
||||
).any? { |f| relative_path == "#{js_root}/#{f}.js" }
|
||||
|
||||
return true if plugin_transpile_paths.any? { |prefix| relative_path.start_with?(prefix) }
|
||||
|
||||
!!(relative_path =~ /^#{js_root}\/[^\/]+\// ||
|
||||
relative_path =~ /^#{test_root}\/[^\/]+\//)
|
||||
end
|
||||
|
Reference in New Issue
Block a user