SASS output from one sass file to multiple css files

五迷三道 提交于 2019-12-05 04:27:31

What about a simple preprocessor in pure ruby (or in any other language you like) which you run before you compile your assets to css?

# gen_schemes_scss.rb    
schemes_scss = File.read('schemes.scss')

%i(light dark moderate).each do |scheme|
  scss = "$scheme: #{scheme};\n" # save current scheme inside scss variable
  scss += schemes_scss # append the rest

  File.write("scheme-#{scheme}.scss", scss) # write to new .scss file
end

With schemes.scss:

$schemes: (
  'light': (
    'body-background': white,
    'headline-color' : #111,
    'subheadline-color': #222
  ),
  'dark': (
    'body-background': black,
    'headline-color' : #ddd,
    'subheadline-color' : #eee
  ),
  'moderate': (
    'body-background': gray,
    'headline-color' : black,
    'subheadline-color' : #333
  )
);

@include scheme-base-mixin($scheme);

The idea is to generate different scss files by this preprocessor. You will have scheme-light.scss, scheme-dark.scss etc. files which can be compiled.

I think a pure sass solution is not possible atm.

I don't think it's possible with sass only. Unless you split the scss files, you will need to use something like gulp.

Using gulp, you can either split the scss files (perhaps using regex) and compile each separately, or split the compiled css files (may be much slower). I can't provide sample code unless you provide an example of your scss.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!