8000 GitHub - ChrishanZ/tuto-sass
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ChrishanZ/tuto-sass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create a html vanilla scss project with gulp compile

1. Create your directory

  mkdir your-directory

2. Create your HTML file

  touch index.html

3. Fill your HTML file

HTML

  <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./style.css">
    <script src="./script.js"></script>
</head>
<body>
    <h1>html vanilla scss project</h1>
</body>
</html>

Make sure to check if everything is working, you can check with live server extension (on vs code : https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)

4. Install gulp and init your project

Inside your directory

  npm install gulp-cli -g 
  npm init -y

If you get some permissions problems

  sudo npm install gulp-cli -g 

5. Create a gulpfile.js

  function defaultTask(cb) {
    console.log("Gulp is working!");
    cb();
  }
  exports.default = defaultTask;

6. Verify if it’s working

  gulp

It should return "Gulp is working!" in your terminal

7. Install the SASS package with the following command

  npm install sass

8. Create a src folder with the following instructions

/src

--->/scss

------>style.scss

  // style.scss
  @import "_global.scss";

------>_global.scss

  // global.scss
  body {
    color: red;
  }

9. Update your gulpfile.js

  const { src, dest, watch } = require("gulp");
  const sass = require("gulp-sass");
  function css() {
    return src("./src/css/*.scss")
      .pipe(sass().on("error", sass.logError))
      .pipe(dest("./dist/assets/"));
  }
  exports.css = css;

10. Then launch gulp command, it should create you a dist folder with some files inside

  gulp

11. If you want to set a watcher

  npm install gulp-watch --save-dev

Change your gulpfie.js

const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const watch = require('gulp-watch');

// Define a task to compile Sass to CSS
gulp.task('css', function () {
    return gulp.src('src/scss/**/*.scss') // Adjust the source path accordingly
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('dist/css')); // Adjust the destination path accordingly
});

// Define a default task
gulp.task('default', gulp.series('css'));

// Define a watch task
gulp.task('watch', function () {
    gulp.watch("./src/scss/**/*.scss", gulp.series('css'));
    // Add additional watch tasks for other source files if needed
});

11. Then you can change your scss and it will automatically refresh your dist/css

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0