📜  scss watch 命令 - CSS (1)

📅  最后修改于: 2023-12-03 15:34:52.832000             🧑  作者: Mango

SCSS Watch Command

Introduction

The SCSS watch command is a feature of SCSS that allows automatic compilation of SCSS files into CSS files whenever changes are made to the SCSS files. This feature is particularly useful for web developers who use SCSS in their projects as it saves time as well as reduces the risk of errors by automating the compilation process.

How to use the SCSS watch command

To use the SCSS watch command, you need to follow these steps:

  1. Open your terminal or command prompt.
  2. Navigate to the directory where your SCSS files are located.
  3. Type the following command: sass --watch [input directory]:[output directory].

For example, if your SCSS files are located in the scss directory and you want the compiled CSS files to be placed in the css directory, the command would look like this:

sass --watch scss:css

This command will watch for changes in any SCSS files in the scss directory and automatically compile them into CSS files in the css directory.

Additional options

The SCSS watch command also offers additional options that can be used to customize the compilation process. Some of these options include:

  • --style [style] - This option sets the output style of the compiled CSS. The available options are nested, expanded, compact, and compressed.
  • --sourcemap [type] - This option generates a sourcemap file that maps the compiled CSS back to the original SCSS file. The available options are auto, file, and inline.
  • --no-source-map - This option disables the generation of sourcemaps.

To use any of these options, simply add them to the end of the SCSS watch command. For example:

sass --watch scss:css --style compressed --sourcemap auto
Conclusion

The SCSS watch command is a powerful feature of SCSS that can save web developers a lot of time and effort. By automatically compiling SCSS files into CSS files, web developers can focus on writing code while SCSS takes care of the compilation process. With the additional customization options, developers can tailor the SCSS watch command to suit their specific needs.