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環境構築

Last updated at Posted at 2018-08-01

自学でコーディングしたいときに、いつも「どうやるんだっけ、、」となって効率が悪いので備忘録としてまとめることにしました。

導入したいタスク

  • sass
  • es2015

gulpfileをes2015で記述する

babelをインストール

yarn add babel --dev

package.jsonにpresetsを書く


"babel": {
    "presets": [
      "env"
    ]
  }

あとはgulpfile.babel.jsに設定をes2015でかける

sass

gulp.sassをインストール

yarn add gulp.sass --dev

設定


gulp.task('sass', () => {
   gulp.src(['./src/**/*.scss', '!./src/**/_*.scss'])
       .pipe(plumber())
       .pipe(sourcemaps.init())
       .pipe(sass({outputStyle: 'compressed'}))
       .pipe(gulp.dest('./build'))
});

babel

gulp.babelをインストール

yarn add gulp-babel babel-core babel-preset-env --dev

設定


gulp.task('babel', () => {
   gulp.src('./src/**/*.js')
       .pipe(plumber())
       .pipe(sourcemaps.init())
       .pipe(babel({
           presets: ['env']
       }))
       .pipe(gulp.dest('./build'))
});

watchとdefaultの設定


gulp.task('watch', ['sass', 'babel'], () => {
    gulp.watch('./src/**', ['sass', 'babel'])
});

gulp.task('default', ['watch']);
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?