1
2

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 を使って style.scss を style.css に変換

Last updated at Posted at 2019-03-24

次のページで行っていることを Arch Linux で確認しました。
絶対つまずかないGulp 4入門(2019年版)

Node.js と npm は既にインストールされているものとします。

$ node --version
v11.12.0
$ npm --version
6.9.0
  1. 作業フォルダーの作成
mkdir gulp-test
cd gulp-test
  1. package.json の作成
npm init -y
  1. ライブラリーのインストール
npm install -D gulp
npm install -D gulp gulp-sass
  1. gulpfile.js の用意
gulpfile.js
// gulpプラグインの読み込み
const gulp = require("gulp")
// Sassをコンパイルするプラグインの読み込み
const sass = require("gulp-sass")

// style.scssをタスクを作成する
gulp.task("default", function() {
  // style.scssファイルを取得
  return (
    gulp
      .src("css/style.scss")
      // Sassのコンパイルを実行
      .pipe(sass(
{
          outputStyle: "expanded"
        }
))
      // cssフォルダー以下に保存
      .pipe(gulp.dest("css"))
  )
})
  1. css/style.scss の用意
css/style.scss
$split-grid: 3;

@for $i from 1 through $split-grid {
  .col-$i {
    flex: 0 0 100% / $split-grid * $i;
    max-width: 100% / $split-grid * $i;
  }
}
  1. css/style.css への変換
npx gulp

css/style.css が作成されます。

css/style.css
.col-$i {
  flex: 0 0 33.33333%;
  max-width: 33.33333%;
}

.col-$i {
  flex: 0 0 66.66667%;
  max-width: 66.66667%;
}

.col-$i {
  flex: 0 0 100%;
  max-width: 100%;
}
1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?