Split up theme SCSS into multiple files

Themes and theme components are becoming steadily more powerful, and developers are getting more and more ambitious. To make things easier for developers, themes can now split their SCSS into multiple files.

https://github.com/discourse/discourse/commit/268d4d4c828a0d9e3ca6b0b5b623db85eb32b9f3

When creating a new theme with the theme CLI, or sharing a theme on github, simply create a new folder called scss. Fill it with your .scss files, following any folder structure, and all the files will be available for you to import in the common / desktop / mobile SCSS sections of your theme.

For example, if you want to have a common variable available to both mobile and desktop SCSS, you could do something like this:

scss/my-folder/variables.scss

$favourite-color = red;

desktop/desktop.scss

@import "my-folder/variables";
body {
  background-color: $favourite-color;
}

mobile/mobile.scss

@import "my-folder/variables";
body {
  color: $favourite-color;
}

This feature was added in v2.3.0.beta8, so do not use these features quite yet if you need to maintain backwards compatibility with older versions of Discourse. You can use the minimum_discourse_version parameter of about.json to ensure your component doesn’t get used on an earlier version.


This document is version controlled - suggest changes on github.

20개의 좋아요

This is amazing @david! Nice work!

I can’t wait to give this a whirl.

8개의 좋아요

This is a great! I can now remove my hack for getting around not being able to do this.

5개의 좋아요

@david this is great, but unfortunately it doesn’t seem to work when the theme is a component. Not sure if that’s a known bug.

You can see it happen with this very simple theme: GitHub - LeoMcA/discourse-multi-scss-component · GitHub

When converted to a stand-alone theme the background colour will be green, but when used as a component within another theme it doesn’t change the background colour at all.

5개의 좋아요

Thanks @LeoMcA, you’re right - this wasn’t working in components. The issue should be fixed in

https://github.com/discourse/discourse/commit/933d2798113c2a54264cf927fc8eabe660bfd17a

4개의 좋아요

그게 여전히 작동해야 하는 건가요? 기본 scss 파일(common/desktop/mobile)에 @import를 추가하면 작동하지 않아요.

아니면 파일을 나누는 방법에 대한 새로운 권장 사항이 있는 건가요?

여전히 작동해야 합니다. 사용 중인 정확한 @import 문구와 스타일시트의 파일 구조를 공유해 주시겠습니까?

테마 설정에는 기본 파일 구조가 있으며, scss/test.scss 파일을 추가했습니다. 그런 다음 @import "test";를 선언했습니다.

콘솔(discourse_theme watch 사용 시)에서 다음 오류가 발생합니다:
✘ Error in common scss: Error: File to import not found or unreadable: test. on line 1 of common.scss

당신의 test.scss 파일에 내용이 있나요?

변수를 하나만 선언했습니다 (참고로, 위 첫 번째 코드 블록에 오타가 있습니다. 등호로 선언되어 있네요: $favourite-color = red;)

하지만 방금 해결했습니다. about.json 파일에서 최소 버전을 v2.3.0.beta8으로 설정해 두었는데, 이 설정을 제거하면 정상적으로 동작합니다. 이 기능을 이전에 사용해 본 적이 없어서 선언 부분에 문제가 있는 건지 정확히 모르겠습니다.

1개의 좋아요

흥미롭네요! 최소 버전을 다시 추가하면 일관되게 문제가 발생합니까? 그렇다면 깨진 테마를 압축해서 여기에 공유해 주시겠어요? (또는 저에게 개인 메시지로 보내주세요)

1개의 좋아요

말씀드린 대로, 저는 이전에 최소 버전 설정을 한 적이 없습니다. 그래서 위에 v2.3.0.beta8로 복사해 넣었습니다. 이렇게 하면 오류가 발생하지만, 2.3.0.beta8은 정상적으로 작동합니다.

node_modules 패키지의 scss 파일을 사용할 수 있나요? 예를 들어:

@import 'bootstrap/scss/bootstrap.scss';
@import '../node_modules/bootstrap/scss/bootstrap.scss';

두 경우 모두 /scss 폴더에서 이 파일을 가져올 수 없습니다.