labofoz
(Oz Ramos)
March 1, 2019, 6:30am
1
Hi! I’m developing a component and can’t seem to @import
additional styles from my MyTheme/common/common.scss
, which contains the following:
@import '../assets/styles/handsfree';
@import '../assets/styles/splash';
My theme component directory looks like:
|-- assets
| |-- styles
| | |-- handsfree.scss
| | |-- splash.scss
|-- common
| |-- common.scss
|-- about.json
|-- settings.yml
Here’s an example of the error I get. I’ve run discourse_theme watch .
in the directory above:
I’ve tried @import
ing with the following:
@import '../assets/styles/handsfree';
@import '/assets/styles/handsfree';
@import 'assets/styles/handsfree';
@import 'styles/handsfree';
Is the import relative to somewhere other than the theme? Basically my common.scss
is getting huge and I’d like to split that up
2 Likes
sam
(Sam Saffron)
March 1, 2019, 6:38am
2
@david has this kind of stuff high on our list, we want theme devs to be able to split off scss files, split of js files to multiple .es6 files and so on.
Current structure is very limiting for ultra advanced usage.
10 Likes
david
(David Taylor)
March 1, 2019, 11:26am
4
Right now it’s impossible to import other files within a theme. As @sam said we are hoping to improve that soon
8 Likes
Thank you @david and @sam
I had the same issue, I thought I did something wrong. Thanks @labofoz for asking.
Hoping to get this thread higher up, I’ll post the error as text.
Error: File to import not found or unreadable: .button.scss.
Parent style sheet: theme_field.scss
on line 1 of theme_field.scss
>> @import '.button';
labofoz
(Oz Ramos)
March 16, 2019, 12:46am
6
Thanks guys! For now, my workaround was to use Webpack to compile all my scripts into one, and then inject that one script inline using this command inside of a template file:
<script>
<%= compilation.assets['main.js'].source() %>
</script>
and the same for SCSS. I turned it into a boilerplate in case anyone else needs it, and wrote more about it here: Discourse-webpack: A boilerplate for developing JS-heavy Discourse components
https://github.com/BrowseHandsfree/discourse-webpack
I organized it in anticipation of making it work seamlessly with the Theme CLI (that’ll be ready in a week or so). My vision with this is to build some components with Vue/React locally and see them pop up live on the Theme Creator!
david
(David Taylor)
April 15, 2019, 4:05pm
7
Multi-file SCSS is now supported natively by our theme system:
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.
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 t…
We hope to add similar functionality for JavaScript assets soon.
8 Likes