Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Sass Setup and Basic Use
Connor Dillon
Connor Dillon

Posted on

     

Sass Setup and Basic Use

How to Set Up Sass Using NPM

  1. In main project folder, (outside of dist folder if using one), create a folder calledscss, andmain.scss file within the newscss folder.

  2. Right click up-one-level folder from dist and open in terminal (i.e. in terminal, go to your dist folder, then do '$ cd ..')

  3. In terminal, do$ npm init to create a package.json file.

  4. Enter package name and details.

  5. In terminal, do$ npm i node-sass to initialize sass.

  6. Openpackage.json file, change:

"scripts":{"test":"echo\"Error: no test specified\" && exit 1"},
Enter fullscreen modeExit fullscreen mode

to:

"scripts":{"sass":"node-sass -w scss/ -o dist/css/ --recursive"},
Enter fullscreen modeExit fullscreen mode

NOTE: File directories in the script must match your folder layout!

For example, if you don't have adist/ folder, just use... -o css/ --recursive instead.

NOTE: Make sure to point your stylesheet correctly in your html code!

For example, if usingmain.scss (and thusmain.css), use:<link rel="stylesheet" href="css/main.css">

  1. In your terminal, start the Sass script with:npm run sass.

  2. Inmain.scss, start writing your sass.

NOTE: Do not edit yourmain.css file. The Sass compiler will overwrite any changes you might make, so be sure to write your CSS directly tomain.scss.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full-stack Javascript developer, fire dancer, physics nerd, Vim fanboy, and technical writer! I'm passionate about my work and love to talk shop, so say hi!
  • Location
    Seattle, WA
  • Work
    Software Engineer
  • Joined

More fromConnor Dillon

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp