gulp 1

gulpとは?
-> Node.jsをベースとしたビルトシステムヘルパー、タスクランナー
-> ブラウザの自動更新もタスクとして処理できる
https://gulpjs.com/

ん?webpackと同じ?ビルトインがある分、webpackの方が高機能か。

gulp install
$ sudo npm i -g gulp
$ gulp -v
CLI version: 2.2.0
$ npm init

gulpfile.js

var gulp = require('gulp');

gulp.task('hello', function(done){
	console.log("hello world");
	done();
});

gulpの3系と4系だと引数の渡し方が異なるようです。

var gulp = require('gulp');

gulp.task('hello', function(done){
	console.log("hello world");
	done();
});

gulp.task('default', gulp.task('hello'));

Sass 4

$totalWidth: 940px;
$columnCount: 5;
@function getColumnWidth($width, $count){
	$padding: 10px;
	$columnWidth: floor($width - ($padding * ($count - 1) / $count));
	@debug $columnWidth;
	@return $columnWidth;
}

.grid {
	float: left;
	width: getColumnWidth($totalWidth, $columnCount);
}
@mixin round {
	border-radius: 4px;
}

.label {
	font-size: 12px;
	@include round;
}
.msg {
	font-size: 12px;
	font-weight: bold;
	padding: 2px 4px;
	color: white;
}

.errorMsg {
	@extend .msg;
	background: red;
}

.warningMsg {
	@extend .msg;
	background: orange;
}
.msg, .errorMsg, .warningMsg {
  font-size: 12px;
  font-weight: bold;
  padding: 2px 4px;
  color: white;
}

.errorMsg {
  background: red;
}

.warningMsg {
  background: orange;
}

OK! 比較的いいペース

Sass 3

lighten, darkenなどが使える

$brandColor: red;

#main {
	width: 90%;
	p {
		color: lighten($brandColor, 30%);
		font-size: 16px;
	}
}
#main {
  width: 90%;
}
#main p {
  color: #ff9999;
  font-size: 16px;
}

sass module
https://sass-lang.com/documentation/modules

if文

$debugMode: true;

#main {
	@if $debugMode == true {
		color: red;
	} else {
		color: green;
	}
}

for

@for $i from 10 through 14 {
.fs#{$i} {font-size: #{$i}px;}
}
$i: 10;
@while $i <= 14 { .fs#{$i} {font-size: #{$i}px;} $i: $i +1; } [/css] [css] $animals: cat, dog, tiger; @each $animal in $animals { .#{$animal}-icon { background: url("#{$animal}.png"); } } [/css]

Sass 2

sassの自動変換
変更があると、上書きされる
[vagrant@localhost sass]$ sass –style expanded –watch scss:css
>>> Sass is watching for changes. Press Ctrl-C to stop.
write css/main.css
write css/main.css.map
>>> Change detected to: scss/main.scss
write css/main.css
write css/main.css.map

あれ、gulpって必要なかったっけ?

/* comment */

#main {
	width: 90%;
	p {
		font-size: 16px;
		a {
			text-decoration: none;
		}
	}
}

&の使い方

a {
			text-decoration: none;
			&:hover {
				font-weight: bold;
			}
		}

変数

$baseFontSize: 14px;

#main {
	width: 90%;
	p {
		font-size: $baseFontSize;
	}
}
$imgDir: "../img/";

#main {
	width: 90%;
	background: url($imgDir + "bg.png");
	p {
		font-size: 16px;
	}
}

Sass 1

Sassとは?
Syntactically Awesome StyleSheet
CSS拡張メタ言語
書き方はSASS記法とSCSS記法がある
SASS記法は拡張子が.sass, ruby like,Haml
SCSSは.scss

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
$ sudo yum install rubygems
$ gem -v
2.5.1
$ gem update –system 2.7.10
$ gem install sass
$ sass -v
Ruby Sass 3.7.4

ファイル構成
– css
— styles.css
– index.html
– scss

#main {
	width: 90%;
	p {
		font-size: 14px;
	}
}

[vagrant@localhost sass]$ sass –style expanded scss/main.scss:css/styles.css
[vagrant@localhost sass]$ cat css/styles.css
#main {
width: 90%;
}
#main p {
font-size: 14px;
}

/*# sourceMappingURL=styles.css.map */

ElementUI 2

Vue.app

<template>
  <div id="app">
    <div class="block">
      <span class="demonstaration">スライダー</span>
      <el-slider v-model="value1"></el-slider>
    </div>

    <div>{{ value1}}</div>

    <span class="demonstration">日付</span>
    <el-date-picker
      v-model="value2"
      type="date"
      placeholder="日付を選んでください">
    </el-date-picker>
  </div>
</template>

<script>
export default {
  name: 'app',
  data(){
    return {
      value1: 50,
      value2: '',
    }
  },
}
</script>

一度環境構築できると、あとが楽になる

ElementUI 1

main.js

import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import locale from 'element-ui/lib/locale/lang/ja'

Vue.config.productionTip = false
Vue.use(ElementUI, {locale})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

App.vue

<template>
  <div id="app">
    <div class="block">
      <span class="demonstaration">スライダー</span>
      <el-slider v-model="value1"></el-slider>
    </div>

    <div>{{ value1}}</div>
  </div>
</template>

<script>
export default {
  name: 'app',
  data(){
    return {
      value1: 50,
    }
  },
}
</script>


jQueryでもあるんだろうけど、書き方としてはこういうことね。

Vue.js 5

vue-cliの中身を見ていきましょう

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>test</title>
  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

main.js

import Vue from 'vue'
import App from './App'
import router from './router'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

あああああああ、react+webpackと同じような仕組みですね。

ん? これはviewの部分か?
App.vue

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App'
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

コンポーネントのルーティング
src/router/index.js

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    }
  ]
})

src/components/Hello.vue

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <h2>Essential Links</h2>
    <ul>
      <li>
        <a
          href="https://vuejs.org"
          target="_blank"
        >
          Core Docs
        </a>
      </li>
      <li>
        <a
          href="https://forum.vuejs.org"
          target="_blank"
        >
          Forum
        </a>
      </li>
      <li>
        <a
          href="https://chat.vuejs.org"
          target="_blank"
        >
          Community Chat
        </a>
      </li>
      <li>
        <a
          href="https://twitter.com/vuejs"
          target="_blank"
        >
          Twitter
        </a>
      </li>
      <br>
      <li>
        <a
          href="http://vuejs-templates.github.io/webpack/"
          target="_blank"
        >
          Docs for This Template
        </a>
      </li>
    </ul>
    <h2>Ecosystem</h2>
    <ul>
      <li>
        <a
          href="http://router.vuejs.org/"
          target="_blank"
        >
          vue-router
        </a>
      </li>
      <li>
        <a
          href="http://vuex.vuejs.org/"
          target="_blank"
        >
          vuex
        </a>
      </li>
      <li>
        <a
          href="http://vue-loader.vuejs.org/"
          target="_blank"
        >
          vue-loader
        </a>
      </li>
      <li>
        <a
          href="https://github.com/vuejs/awesome-vue"
          target="_blank"
        >
          awesome-vue
        </a>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

気を取り直してkeep going

Vue.js 4

ElementUIとは
=>Vue.jsのコンポーネントライブラリ
Vue CLIを使う?
=>インタラクティブなプロジェクトの作成

$ sudo npm install -g vue-cli
$ vue –version
2.9.6

vue init template project-name でプロジェクトを作成する

$ vue init webpack test

? Project name test
? Project description A Vue.js project
? Author
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Set up unit tests No
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been created? (recom
mended) npm

vue-cli · Generated “test”.

$ npm run dev
Your application is running here: http://localhost:8080

なに?表示されない?
/config/index.jsのhostを編集

host: '192.168.34.10', // can be overwritten by process.env.HOST
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, 

ほう

Vue.js 3

(function(){
	'use strict';

	var likeComponent = Vue.extend({
		template : '<button>like</button>'
	});

	var app = new Vue({
		el: '#app',
		components: {
			'like-component': likeComponent
		}
	});
})();
(function(){
	'use strict';

	var likeComponent = Vue.extend({
		data: function(){
			return {
				count: 0
			}
		},
		template : '<button @click="countUp">like {{ count }}</button>',
		methods: {
			countUp: function(){
				this.count++;
			}
		}
	});

	var app = new Vue({
		el: '#app',
		components: {
			'like-component': likeComponent
		}
	});
})();
(function(){
	'use strict';

	var likeComponent = Vue.extend({
		props: {
			message: {
				type: String,
				default: 'Like'
			}
		},
		data: function(){
			return {
				count: 0
			}
		},
		template : '<button @click="countUp">{{ message }} {{ count }}</button>',
		methods: {
			countUp: function(){
				this.count++;
			}
		}
	});

	var app = new Vue({
		el: '#app',
		components: {
			'like-component': likeComponent
		}
	});
})();
(function(){
	'use strict';

	var likeComponent = Vue.extend({
		props: {
			message: {
				type: String,
				default: 'Like'
			}
		},
		data: function(){
			return {
				count: 0
			}
		},
		template : '<button @click="countUp">{{ message }} {{ count }}</button>',
		methods: {
			countUp: function(){
				this.count++;
				this.$emit('increment');
			}
		}
	});

	var app = new Vue({
		el: '#app',
		components: {
			'like-component': likeComponent
		},
		data: {
			total: 0
		},
		methods: {
			incrementTotal: function(){
				this.total++;
			}
		}
	});
})();