Skip to content

Instantly share code, notes, and snippets.

@cognitom
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognitom/335bfadd750fc1db38c0 to your computer and use it in GitHub Desktop.
Save cognitom/335bfadd750fc1db38c0 to your computer and use it in GitHub Desktop.
Browserify: それはrequire()を使うための魔法の杖 ref: http://qiita.com/cognitom/items/4c63969b5085c90639d4
Modernizr = require 'browsernizr' # npm経由
$ = require 'jquery' # bower経由
require './yourscript' # サイト用のスクリプト
# ここに書き足してもOK
console.log 'This page is ' + $('H1').text()
gulp = require 'gulp'
browserify = require 'browserify'
source = require 'vinyl-source-stream'
gulp.task 'script', ->
browserify
entries: ['./js/src/main.coffee']
extensions: ['.coffee'] # CoffeeScriptも使えるように
.bundle()
.pipe source 'main.js' # 出力ファイル名を指定
.pipe gulp.dest "./js/" # 出力ディレクトリを指定
{
<略>
"browserify": {
"transform": [
"coffeeify",
"debowerify"
]
},
"devDependencies": {
"coffee-script": "*",
"vinyl-source-stream": "*",
"gulp": "*",
"bower": "*",
"browserify": "*",
"coffeeify": "*",
"debowerify": "*",
"browsernizr": "*"
}
}
{
<略>
"dependencies": {
"jquery": "*"
}
}
$ npm install && bower install
$ gulp script
$ npm install -g browserify
$ browserify main.js -o bundle.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment