1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GulpでSassを動かす方法(Mac)

Last updated at Posted at 2016-09-30

#「Gulp」で「Sass」を動かす方法(Mac)

####1. nodeをインストール(node_install

####2. package.jsonの作成

>> npm init

####3. gulp_install

>> npm install gulp -g

####4. local_gulp_install

>> npm install gulp --save-dev

####5. gulpfile.jsの作成

gulpfile.js
var gulp = require('gulp');

####6. SASSコンパイル

>> sass/style.scss

####7. gulp-sass

>> npm install gulp-sass --sass-dev

####8. gulpfile.jsの作成

gulpfile.js
var gulp = require('gulp');
var sass = require('sass');

gulp.task('sass', function() {
     gulp.src('sass/**/*.scss')
      .pipe(sass())
      .pipe(gulp.dest('./css'))
});

####9. gulp-autoprefixer

>> npm install gulp-autoprefixer --save-dev

####10. gulpfile.jsの作成

gulpfile.js
var gulp = require('gulp');
var sass = require('sass');
var autoprefixer = require('gulp-autoprefixer');

gulp.task('sass', function() {
     gulp.src('sass/**/*.scss')
      .pipe(sass())
      .pipe(gulp.dest('./css'))
      .pipe(autoprefixer())
});

####11. gulp-frontnote

>> npm install gulp-frontnote --save-dev

####12. gulpfile.jsの作成

gulpfile.js
var gulp = require('gulp');
var sass = require('sass');
var autoprefixer = require('gulp-autoprefixer');
var frontnode = require('gulp-frontnode');

gulp.task('sass', function() {
     gulp.src('sass/**/*.scss')
      .pipe(sass())
      .pipe(gulp.dest('./css'))
      .pipe(autoprefixer())
      .pipe(frontnote({
           css: '../css/style.css'
      }))
});

####13. jsの圧縮

>> npm install gulp-uglify --save-dev

####14. gulpfile.jsの作成

gulpfile.js
var gulp = require('gulp');
var sass = require('sass');
var autoprefixer = require('gulp-autoprefixer');
var frontnode = require('gulp-frontnode');
var uglify = require('gulp-uglify');

gulp.task('html', function() {
     gulp.src('**/*.html')
});

gulp.task('js', function() {
     gulp.src(['js/**/*.js', '!js/min/**/*.js'])
     .pipe(uglify())
     .pipe(gulp.dest('./js/min'));
});

gulp.task('sass', function() {
     gulp.src('sass/**/*.scss')
      .pipe(sass())
      .pipe(gulp.dest('./css'))
      .pipe(autoprefixer())
      .pipe(frontnote({
           css: '../css/style.css'
      }))
});

####15. gulpfile.jsの作成(file監視)

gulpfile.js
var gulp = require('gulp');
var sass = require('sass');
var autoprefixer = require('gulp-autoprefixer');
var frontnode = require('gulp-frontnode');
var uglify = require('gulp-uglify');
var browser = require('browser-sync');

gulp.task('html', function() {
     gulp.src('**/*.html')
});

gulp.task('js', function() {
     gulp.src(['js/**/*.js', '!js/min/**/*.js'])
     .pipe(uglify())
     .pipe(gulp.dest('./js/min'));
});

gulp.task('sass', function() {
     gulp.src('sass/**/*.scss')
      .pipe(sass())
      .pipe(gulp.dest('./css'))
      .pipe(autoprefixer())
      .pipe(frontnote({
           css: '../css/style.css'
      }))
});

gulp.task('default', function() {
     gulp.watch('**/*.html', ['html']);
     gulp.watch(['js/**/*.js'], ['js']);
     gulp.watch('sass/**/*.scss', ['sass']);
});

####16. LiveReload

>> npm install browser-sync --save-dev

####17. gulpfile.jsの作成(Reload)

gulpfile.js
var gulp = require('gulp');
var sass = require('sass');
var autoprefixer = require('gulp-autoprefixer');
var frontnode = require('gulp-frontnode');
var uglify = require('gulp-uglify');
var browser = require('browser-sync');

gulp.task('server', function() {
     browser({
          server: {
               baseDir: './';
               directory: true
          },
                    startPath: 'index.html'
     });
});

gulp.task('html', function() {
     gulp.src('**/*.html')
     .pipe(browser.reload({stream: true}))
});

gulp.task('js', function() {
     gulp.src(['js/**/*.js', '!js/min/**/*.js'])
     .pipe(uglify())
     .pipe(gulp.dest('./js/min'))
     .pipe(browser.reload({stream: true}))
});

gulp.task('sass', function() {
     gulp.src('sass/**/*.scss')
      .pipe(sass())
      .pipe(gulp.dest('./css'))
      .pipe(autoprefixer())
      .pipe(frontnote({
           css: '../css/style.css'
      }))
     .pipe(browser.reload({stream: true}))
});

gulp.task('default', ['server'], function() {
     gulp.watch('**/*.html', ['html']);
     gulp.watch(['js/**/*.js'], ['js']);
     gulp.watch('sass/**/*.scss', ['sass']);
});

####18. エラー時落とさないようにする

>> npm install gulp-plumber --save-dev

####19. gulpfile.jsの作成(エラー時落とさないようにする)

gulpfile.js
var gulp = require('gulp');
var sass = require('sass');
var autoprefixer = require('gulp-autoprefixer');
var frontnode = require('gulp-frontnode');
var uglify = require('gulp-uglify');
var browser = require('browser-sync');
var plumber = require('gulp-plumber');

gulp.task('server', function() {
     browser({
          server: {
               baseDir: './';
               directory: true
          }
     });
});

gulp.task('html', function() {
     gulp.src('**/*.html')
     .pipe(browser.reload({stream: true}))
});

gulp.task('js', function() {
     gulp.src(['js/**/*.js', '!js/min/**/*.js'])
     .pipe(uglify())
     .pipe(gulp.dest('./js/min'))
     .pipe(browser.reload({stream: true}))
});

gulp.task('sass', function() {
     gulp.src('sass/**/*.scss')
      .pipe(sass())
      .pipe(gulp.dest('./css'))
      .pipe(autoprefixer())
      .pipe(frontnote({
           css: '../css/style.css'
      }))
     .pipe(plumber())
     .pipe(browser.reload({stream: true}))
});

gulp.task('default', ['server'], function() {
     gulp.watch('**/*.html', ['html']);
     gulp.watch(['js/**/*.js'], ['js']);
     gulp.watch('sass/**/*.scss', ['sass']);
});

####20. gulp実行

>> gulp
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?