Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
フロントエンド制作向け ビルドツールGruntを PHPバックエンド開発で利用する @M_Is...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
M_Ishikawa
September 14, 2013
Technology
240
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
フロントエンド制作向け ビルドツールGruntを PHPバックエンド開発で利用する @M_Ishikawa #phpcon2013
PHPカンファレンス2013 発表資料
#phpcon2013
php, grunt, phpcon, phpcon2013, nodejs, node, composer
M_Ishikawa
September 14, 2013
More Decks by M_Ishikawa
See All by M_Ishikawa
Socialiteのベストプラクティス
ishikawam
0
150
サンタクロースを支えるIT技術 @M_Ishikawa #yapcasia
ishikawam
0
140
WebPayのCheckoutHelper が超便利!!! って話
ishikawam
0
140
IPtalkの使い方
ishikawam
0
600
フロントエンド制作向けビルド ツールGruntがバックエンド 開発でも意外と使える! @M_Ishikawa #yapcasia
ishikawam
1
11k
Other Decks in Technology
See All in Technology
アプリログインとWeb認証基盤をつなぐ ASWebAuthenticationSession 作法
shimastripe
1
290
Claude Code本って、 読む必要あるの?
oikon48
2
440
現場で役立つ技術負債の効果的な返済方法
masuda220
PRO
1
110
Microsoft 365 Copilot chat -tekoälypalvelun tietosuojaongelmat
hponka
0
840
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
3
490
クロスボーダーM&AのValue Upを支えるプロダクト開発。日米チームのハブになったプロダクトエンジニアの実践 / Product Engineering Conference 2026
genda
0
120
20260912_スクフェス三河
kgnkhkr
0
340
2026-09-11 【Snowflake World Tour Tokyo 2026】Snowflakeを起点に、AI Agentが自律稼働し続ける未来へ / Driving AI Agents with Snowflake
civitaspo
0
390
AIで仕事のやり方を変える
matsu7874
3
1.1k
【技術的負債conf】事業成長に伴う技術的負債の説明責任とAIによるモニタリング、認知的負債について
i35_267
1
250
株式会社シーエーシー エンジニア向け会社紹介資料
cac
0
57k
2026-09-10 【Snowflake World Tour Tokyo 2026】dbt Core と Snowflake で実現する多層的なデータガバナンス / Multi-Layered Data Governance Powered by dbt Core and Snowflake
civitaspo
0
370
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
520
Facilitating Awesome Meetings
lara
57
7.1k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
790
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
520
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Building the Perfect Custom Keyboard
takai
2
870
GitHub's CSS Performance
jonrohan
1033
470k
Become a Pro
speakerdeck
PRO
31
6.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Transcript
フロントエンド制作向け ビルドツールGruntを PHPバックエンド開発で利利⽤用する @M_̲Ishikawa 2013/9/24 (Ր)
本⽇日の⽬目標 •Gruntがなにかを知る •PHP開発でGruntの使い道を知る •Gruntプラグインを⾃自分で開発できる ようにする ⼊入⾨門者向けの内容です 2013/9/24 (Ր)
• ⾃自⼰己紹介 • Gruntとは • Grunt概要 • Gruntプラグイン • 活⽤用事例例
• バックエンド開発での利利⽤用 • 事例例 • PHP関連プラグイン 本⽇日のメニュー 2013/9/24 (Ր)
⾃自⼰己紹介 2013/9/24 (Ր)
•Masayuki Ishikawa •@M_̲Ishikawa •id:ishikawam •ブラウザソーシャルゲームの開発エンジニア 2013/9/24 (Ր)
Gruntとは 2013/9/24 (Ր)
http://gruntjs.com/ 2013/9/24 (Ր)
•最近のHTMLとかCSSのイベント・カンファレンスで 使っているのをよく⾒見見かける •講演内容がGruntではなくても、講演者はGrunt使⽤用 が前提でセッションを進めてたり •フロントエンド開発では結構当たり前に使っている •デザイナーが「⿊黒い画⾯面」といいだしたのはGruntを 触るのがきっかけ?(実際はcompassとかsassとか gitとかだけど) でも我々PHPerにはほとんど縁がない! 2013/9/24
(Ր)
• node.js製のフロントエンド開発⽀支援ツール • フロントエンド関連ファイルのビルドを⾏行行う • 開発⽤用、公開⽤用ディレクトリを分けて管理理し、公開⽤用に画像を圧 縮したりJSを難読化したりCSSプリプロセッサ変換(Sass等) をしたりテストしたり etc... •
プラグインによりツールを拡張できる • プラグインの開発が簡単(node=JS) • Gruntプラグイン=nodeモジュールなのでnpmで管理理されてます Gruntとは 2013/9/24 (Ր)
•依存管理理といったら例例えばこんなの •PEARとかGemは?>パッケージ管理理。 •※npmはパッケージ管理理、依存管理理の両⽅方できる •git submoduleではなく機能として利利⽤用できる npm のおさらい ライブラリの依存管理理 2013/9/24 (Ր)
Gruntの動作環境 •開発環境で使う •nodeが動けば動く。Macでも、 Windowsでも、Linuxでも •今回はクライアントMacでデモ •サーバ上での開発で使⽤用しても まったく問題なし 2013/9/24 (Ր)
•デザイナーがMacで制作、Sublime Text を使⽤用して⿊黒い画⾯面でGruntを利利⽤用 •エンジニアがターミナルから接続した開発 ⽤用サーバ上でプログラミング、そこで Gruntを利利⽤用 例例えばこんなシチュエーション 2013/9/24 (Ր)
•Gruntは枠組みだけ、実態はプラグイ ンで、これをどう使うか。 •http://gruntjs.com/plugins •公式 25 •全体 1390 ※npm search gruntplugin
| wc -‐‑‒l 調べ 2013/9/12現在 Gruntプラグイン 2013/9/24 (Ր)
• grunt-‐‑‒contrib(公式プラグイン:25個)でどんなことができるか https://github.com/gruntjs/grunt-‐‑‒contrib • grunt-‐‑‒contrib-‐‑‒clean Clean files and folders. •
grunt-‐‑‒contrib-‐‑‒coffee Compile CoffeeScript files to JavaScript. • grunt-‐‑‒contrib-‐‑‒compass Compile Compass to CSS • grunt-‐‑‒contrib-‐‑‒compress Compress files and folders. • grunt-‐‑‒contrib-‐‑‒concat Concatenate files. • grunt-‐‑‒contrib-‐‑‒connect Start a connect web server. • grunt-‐‑‒contrib-‐‑‒copy Copy files and folders. • grunt-‐‑‒contrib-‐‑‒cssmin Compress CSS files. • grunt-‐‑‒contrib-‐‑‒csslint Lint CSS files. • grunt-‐‑‒contrib-‐‑‒handlebars Precompile Handlebars templates to JST file. • grunt-‐‑‒contrib-‐‑‒htmlmin Minify HTML • grunt-‐‑‒contrib-‐‑‒imagemin Minify PNG and JPEG images • grunt-‐‑‒contrib-‐‑‒jade Compile Jade files to HTML. • grunt-‐‑‒contrib-‐‑‒jasmine Run jasmine specs headlessly through PhantomJS. • grunt-‐‑‒contrib-‐‑‒jshint Validate files with JSHint. • grunt-‐‑‒contrib-‐‑‒jst Precompile Underscore templates to JST file. • grunt-‐‑‒contrib-‐‑‒less Compile LESS files to CSS. • grunt-‐‑‒contrib-‐‑‒nodeunit Run Nodeunit unit tests. • grunt-‐‑‒contrib-‐‑‒qunit Run QUnit unit tests in a headless PhantomJS instance. • grunt-‐‑‒contrib-‐‑‒requirejs Optimize RequireJS projects using r.js. • grunt-‐‑‒contrib-‐‑‒sass Compile Sass to CSS • grunt-‐‑‒contrib-‐‑‒stylus Compile Stylus files to CSS. • grunt-‐‑‒contrib-‐‑‒uglify Minify files with UglifyJS. • grunt-‐‑‒contrib-‐‑‒watch Run predefined tasks whenever watched file patterns are added, changed or deleted. • grunt-‐‑‒contrib-‐‑‒yuidoc Compile YUIDoc Documentation. 2013/9/24 (Ր)
様々なコンバート処理理 nodeunit uglifyjs 2013/9/24 (Ր)
• 開発、運⽤用において、「コードを書く以外」でやっている⼿手間ありま せんか? • コンパイル、ビルドのコマンド実⾏行行 • Sass(SCSS,less)を変換、CoffeeScriptを変換 • 本番配布⽤用に画像の圧縮、JSの難読化、CSSのミニファイ •
規則正しく予想できるファイル名(card1.png,card2.png,...) へ直接アクセスされないように隠蔽するのにハッシュのリネーム • CDNのキャッシュをクリアするために⾛走らせているコマンド • srcにパラメータ付与、ファイル名変更更、等 • テストの実⾏行行 • Lint, シンタックスチェック, UNITテスト,等 • その他、無限の可能性が...!!! Gruntの使いどころ 2013/9/24 (Ր)
•1.開発環境へnode、Gruntを導⼊入 •ちなみに本番運⽤用サーバへnodeを⼊入れる必要は ありません!あくまで開発⽀支援で使うのみです。 •2.プロジェクトリポジトリへGruntfile.jsと package.jsonを⼊入れて、node_̲modules を.gitignoreに⼊入れる •3.各開発環境では npm install を実⾏行行して
node_̲modules以下にGruntプラグインを構築 Grunt導⼊入までの流流れ 2013/9/24 (Ր)
# node͕ೖ͍ͬͯΔલఏ % npm -g install grunt-cli % mkdir ~/hoge
% cd ~/hoge % npm install grunt --save 1.開発環境へGruntを導⼊入 npmのお作法により、プロジェクトごとにインストールする 2013/9/24 (Ր)
•Gruntfile.js •Gruntの設定ファイル •package.json •Gruntで使⽤用するプラグインのパッ ケージ管理理&依存管理理 2.プロジェクトへ Gruntfile.js と package.json
を設置 2013/9/24 (Ր)
% npm install 3.node_̲modules以下に Gruntプラグインを構築 package.json 正しく書かれていれば node_̲modules ディレクトリ 以下にプラグインがインストールされます。
2013/9/24 (Ր)
Gruntデモ ソース公開してます https://github.com/ishikawam/grunt-‐‑‒sample-‐‑‒php 2013/9/24 (Ր)
Gruntのデモ • Wordpressで試します • 今回使⽤用するプラグイン • gruntでミニファイ • grunt-‐‑‒contrib-‐‑‒cssmin •
grunt-‐‑‒contrib-‐‑‒uglify • gruntで構⽂文チェック • grunt-‐‑‒contrib-‐‑‒csslint • grunt-‐‑‒contrib-‐‑‒jshint • gruntでPHP! • grunt-‐‑‒phpunit • grunt-‐‑‒phplint • grunt-‐‑‒phpcs 2013/9/24 (Ր)
Gruntでミニファイ • プラグイン例例 • grunt-‐‑‒contrib-‐‑‒cssmin cssのミニファイ • grunt-‐‑‒contrib-‐‑‒uglify JSのミニファイ •
grunt-‐‑‒contrib-‐‑‒imagemin png,jpgのミニファイ • ファイル構成例例 • htdocs/{css,js,img}/ DocmentRoot • assets/{css,js,img}/ オリジナルファイル ※開発⽤用としてはメディアファイルをhtdocsではなく assetsを参照するようにすれと捗ります。 2013/9/24 (Ր)
Gruntで構⽂文チェック •本⽇日の例例 •grunt-‐‑‒contrib-‐‑‒csslint •cssの構⽂文チェック •grunt-‐‑‒contrib-‐‑‒jshint •JSの構⽂文チェック ※チェッカの設定はGruntfile.js内 Optionsで細かく指定できます。 2013/9/24 (Ր)
GruntでPHP! •本⽇日の例例 •grunt-‐‑‒phpunit •PHPのユニットテスト •grunt-‐‑‒phplint •PHPの構⽂文チェック •grunt-‐‑‒phpcs •PHPのコーディング規約チェック ※他にもPHP関連Gruntプラグインはあります 2013/9/24
(Ր)
例例:PHPのソースを監視して ユニットテストを⾛走らせる 2013/9/24 (Ր)
例例:PHPのソースを監視して ユニットテストを⾛走らせる grunt-‐‑‒watchでソースの変更更を監視して phpunitをgrunt-‐‑‒phpunitを介して実⾏行行する = 2013/9/24 (Ր)
Gruntプラグインを 作ってみよう 2013/9/24 (Ր)
•やりたいこと:grunt-‐‑‒watchでソースの変 更更を監視してphpunitをgrunt-‐‑‒phpunitを 介して実⾏行行する •「こんなのあるかな?」と思ったプラグイ ンはだいたい存在する (なければ作れば いいよ) Gruntプラグインを 作ってみよう 2013/9/24
(Ր)
Gruntプラグインのファイル構成例例 • Gruntfile.js • package.json • README.* • LICENSE-‐‑‒* •
tasks/ • node_̲modules/ • .git • .gitignore • .npmignore • .travis.yml • test/ • tmp/ 2013/9/24 (Ր)
Gruntプラグインの開発にも Gruntを使います 2013/9/24 (Ր)
% npm init #package.jsonΛੜ % npm publish #ެ։ʂ % npm
info hoge #npmʹొ͞ΕͨͷΛ֬ೝ 1.開発環境へGruntを導⼊入 たったこれだけ! 2013/9/24 (Ր)
Gruntで楽しい コーディングライフを!! 2013/9/24 (Ր)
本⽇日のサンプルはGithubで 資料料はslideshareで 公開してます。 http://www.slideshare.net/mishikawa55/2013-‐‑‒phpcon https://github.com/ishikawam/grunt-‐‑‒sample-‐‑‒php 2013/9/24 (Ր)
以上、ご清聴 ありがとうございました! @M_̲Ishikawa 2013/9/24 (Ր)
以上、ご清聴 ありがとうございました! @M_̲Ishikawa 2013/9/24 (Ր)