Jekyll doesn't compile scss files with `jekyll serve`

风格不统一 提交于 2019-12-21 05:13:11

问题


I'm trying to create a website using Jekyll, and everything worked fine. Until I wanted to custom the design.

I've updated my css/main.scss in order to include my custom theme in _sass/theme.scss:

// Import partials from `sass_dir` (defaults to `_sass`)
@import
        "base",
        "layout",
        "syntax-highlighting",
        "theme"
;

I've also updated _config.yml, because jekyll serve -H 0.0.0.0 didn't compile my new sass file. I've added the following:

sass:
    sass_dir: _sass

The problem is jekyll serve doesn't compile my sass files, I always see the default css. I've also tried to copy the content of _sass/theme.scss directly at the end of css/main.scss, but nothing happened.

Until I modified one of those files while jekyll serve was running. The thing is jekyll-watch understands my updates and compile the scss files. May I have done something wrong for jekyll build don't compile sass files at the first try?

In case you need it, here my project tree:

.
├── _config.yml
├── css
│   ├── main.css
│   └── main.scss
├── _images
├── img
├── index.html
└── _sass
    ├── _base.scss
    ├── _layout.scss
    ├── _syntax-highlighting.scss
    └── _theme.scss

Does someone know how to fix this?

Thank you,


回答1:


Ok, I get it !

You have a css/main.css files that is copied as a static file in _site/css/main.css.

The problem is that it has the same name as the css/main.scss target which is also _site/css/main.css.

So at first build :

  • css/main.scss is processed to main.css
  • then, when static files are copied, it is overridden by css/main.css.

Solution : delete css/main.css




回答2:


Have you added the front matter to the top of your main.scss file?




回答3:


First add to your config.yml

sass:
    sass_dir: _sass

Then add to top in your main.scss file, two dashed lines https://jekyllrb.com/docs/assets/

---
---

@charset "utf-8";

After that write in your cmd console

jekyll serve

and check your compilation.



来源:https://stackoverflow.com/questions/38437416/jekyll-doesnt-compile-scss-files-with-jekyll-serve

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