DEV: Use separate files for theme component stylesheets (#12214)

This switches to outputting a separate file for each theme component CSS
asset. We have separate CSS plugin files, separate JS files
(for plugins/themes/components), it makes sense to do the same for
component CSS assets.

Benefits:
- easier debugging
- fixes a regression with theme component sourcemaps
- changes to theme components are updated individually

With HTTP/2, there is also no performance downside to having additional
files in the initial request.
This commit is contained in:
Penar Musaraj
2021-02-26 07:44:15 -05:00
committed by GitHub
parent bb3d5e9758
commit f57a49c2f9
6 changed files with 41 additions and 31 deletions

View File

@ -194,18 +194,13 @@ module Stylesheet
fields.map do |field|
value = field.value
if value.present?
filename = "theme_#{field.theme.id}/#{field.target_name}-#{field.name}-#{field.theme.name.parameterize}.scss"
contents << <<~COMMENT
// Theme: #{field.theme.name}
// Target: #{field.target_name} #{field.name}
// Last Edited: #{field.updated_at}
COMMENT
if field.theme_id == theme.id
contents << value
else
contents << field.compiled_css(prepended_scss)
end
contents << value
end
end

View File

@ -58,7 +58,7 @@ class Stylesheet::Manager
theme_ids = [theme_ids] unless Array === theme_ids
theme_ids = [theme_ids.first] unless target =~ THEME_REGEX
theme_ids = Theme.transform_ids(theme_ids, extend: false)
theme_ids = Theme.transform_ids(theme_ids)
current_hostname = Discourse.current_hostname