Sass Preprocessing
本文最后更新于:2021年2月19日 晚上
Sass Preprocessing
CSS on its own can be fun, but stylesheets are getting larger, more complex, and harder to maintain. This is where a preprocessor can help. Sass lets you use features that don’t exist in CSS yet like variables, nesting, mixins, inheritance and other nifty goodies that make writing CSS fun again.
Once you start tinkering with Sass, it will take your preprocessed Sass file and save it as a normal CSS file that you can use in your website.
The most direct way to make this happen is in your terminal. Once Sass is installed, you can compile your Sass to CSS using the sass
command. You’ll need to tell Sass which file to build from, and where to output CSS to. For example, running sass input.scss output.css
from your terminal would take a single Sass file, input.scss
, and compile that file to output.css
.
You can also watch individual files or directories with the --watch
flag. The watch flag tells Sass to watch your source files for changes, and re-compile CSS each time you save your Sass. If you wanted to watch (instead of manually build) your input.scss
file, you’d just add the watch flag to your command, like so:
1 |
|
You can watch and output to directories by using folder paths as your input and output, and separating them with a colon. In this example:
1 |
|
Sass would watch all files in the app/sass
folder for changes, and compile CSS to the public/stylesheets
folder.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!