htmlsassstyles

how to make multiple pages with sass?


I want to have 2 pages with their own style using sass. now I have a main.scss file and all styles will be compiled in style.css with this command in package.json "watch:sass": "node-sass sass/main.scss css/style.css", if I want to have another page I can still use this main.scss file but when I load this page all style of the first page will be come with style.css. may I have two separate main.scss file for each page? if yes how should I change "watch":sass "node-sass sass/main.scss css/style.css",

my second question is how can I use common styles like for header and footer which are in both pages?

UPDATE I created 2 main.scss file. and 2 separated style.css and put them beside each other . and I modified my watch script like this:

"watch:sass": "node-sass --watch sass/main.scss:css/style.css sass/main2.scss:css/style2.css"

my first main.scss and style.scss works but the second main.scss and style2.css does not work


Solution

  • I created another main.scss file called it main2.scss. I modified the watch script like this:

     "watch:sass": "sass --watch sass/main2.scss:css/style2.css sass/main.scss:css/style.css",
    

    now I can use style2.css for page 2 and in this way for page 2 I will load only relevant CSS stylse for only page 2.

    Don't forget to stop npm start and re run it again

    I read somewhere that it's good to have only one CSS file for all pages for the sake of browser cache, etc. but in this way I have separated CSS for each page.