简体   繁体   中英

Partial Compiling of SCSS file into CSS

I use lates Vscode with the extension "live SASS Compiler". I want to use bootstrap, so I linked a style.css file in html, which is supposed to have all the compiled bootstrap.css codes (including mine). To customize the Bootstrap theme, I have another style.scss file which imports the local bootstrap.scss file. Now after the import of local bootstrap.scss file in style.scss, I compiled/transpiled (watched) the scss file into style.css file, which works but partially, only the portion of extra scss code I added is transpiled to css, excluding all the bootstrap.css code. That's why my html is not getting bootstrap with style.css.

I am mentioning the portion of code for the simplicty. This is the html file:

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Bootstrap Site</title>
  <link rel="stylesheet" href="/src/css/style.css" />
</head>

This is style.scss file, I watch/transpile this style.scss into style.css

@import url(/node_modules/bootstrap/scss/bootstrap.scss);
$bg-color: rgb(221, 204, 117);
$font-color: rgb(170, 12, 12);
body {
  background-color: $bg-color;
  color: $font-colo; 
}

This is the transpiled style.css file (with only the portion of code transpiled):

@import url(/node_modules/bootstrap/scss/bootstrap.scss);
body {
  background-color: #ddcc75;
  color: #aa0c0c;
}

As you can see the transpiled style.css file doesnt have all the bootstrap css codes, which is why the html is not linked with bootstrap (Bootstrap works only if I link it separately in another link tag). How do I make it work with style.css for the bootstrap theme customization?

NB Its NPM project, I used NPM to download bootstrap.

This is how I get it to work. I changed the scss file's code to something much simpler and made sure that the bootstrap.scss is located correctly. But I changed the path to this @import "/node_modules/bootstrap/scss/bootstrap"; I am not sure if it matters but I used bootstrap.scss earlier in the path. I dont know if adding/removing the extension (.scss) matters! I also installed SASS from NPM globally, thats why, I am still not sure what exactly made it right - the code in scss file or the extension in the path!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM