Sass

Sass is a CSS extension that allows you to use variables , nested rules , mixins , inline imports and other functions based on CSS syntax to make CSS more powerful and elegant..

Using Sass and the Compass style library can help better organize and manage style files and develop projects more efficiently.

sass docs

Plugin Installation

In HBuilderX, the use of scss/sass requires the installation of the compile-node-sass compilation plugin. This plugin can compile scss/sass to css.

compile-node-sass Download

How to use

  • The uni-app project will automatically compile files that use sass。
  • How to compile the sass file separately. Select the sass file, right-click and choose menu -> External Commands -> Scss/Sass compilation -> Compile Scss/Sass.

Sass - 图1

Configuration File

The configuration file of compile-node-sass is package.json.

Click the menu [Tools -> External Command Setting -> compile-node-sass -> package.json] to open the package.json file.

Sass - 图2

  1. {
  2. "name": "sass",
  3. "id": "compile-node-sass",
  4. "version": "0.0.7",
  5. "displayName": "%displayName%",
  6. "description": "%description%",
  7. "engines": {
  8. "HBuilderX": "^3.2.6"
  9. },
  10. "external": {
  11. "type": "node",
  12. "programPath": "${pluginPath}",
  13. "executable": "/node_modules/.bin/node-sass",
  14. "programName": "node-sass-china",
  15. "commands": [
  16. {
  17. "id": "SASS_COMPILE",
  18. "name": "%SASS_COMPILE.name%",
  19. "command": [
  20. "${programPath}",
  21. "${file}",
  22. "${fileBasename}.css"
  23. ],
  24. "extensions": "scss,sass",
  25. "key": "",
  26. "showInParentMenu": false,
  27. "onDidSaveExecution": false
  28. }
  29. ]
  30. },
  31. "dependencies": {
  32. "node-sass-china": "^4.7.2"
  33. },
  34. "extensionDependencies": [
  35. "npm"
  36. ]
  37. }

Shortcut Keys

Click the menu [Tools -> External Command Setting -> compile-node-sass -> package.json] to open the package.json file.

Open package.json and modify the key value to configure the shortcut key; this external command can be run directly through this shortcut key. For example: "key": "ctrl + alt + C"

Save and Compile

Click the menu [Tools -> External Command Setting -> compile-node-sass -> package.json] to open the package.json file.

The onDidSaveExecution in the configuration file indicates whether to trigger compilation when saving, and the default is false.

Modify onDidSaveExecution to true.