SlideShare a Scribd company logo
1 of 71
Introduction to
Using NPM scripts
as a Build Tool.
/@kjy2143 SK planet
1 . 1
1 . 2
1 . 3
1 . 4
Front End Developer
in Past
2 . 1
2 . 2
Front End Developer
in 2016
3 . 1
3 . 2
2016/2017 MUST-KNOW
WEB DEVELOPMENT TECH
CSS Preprocessor Compile
ES2016+ Compile
Optimization
Linting
Unit Testing
Module Bundling
Package Management
3 . 3
skpui:js
3 . 4
skpui:css
3 . 5
skpui:test
3 . 6
JavaScript Uglify
npm install uglify-js -g
uglifyjs foo.js -o foo.min.js
3 . 7
JavaScript Linting
npm install jshint -g
npm install jshint-stylish --save-dev
jshint --reporter=node_modules/jshint-stylish foo.js
3 . 8
Command Line Interface
CSS Preprocessor Compile
ES2016+ Compile
Optimization
Linting
Unit Testing
Module Bundling
Package Management
3 . 9
Automation
4 . 1
GRUNT
The JavaScript Task Runner
4 . 2
Gruntfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %
},
build: {
src: 'src/<%= pkg.name %>.js',
dest: 'build/<%= pkg.name %>.min.js'
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default', ['uglify']);
};
4 . 3
grunt
4 . 4
Automate and enhance your workflow
4 . 5
gulpfile.babel.js
import gulp from 'gulp';
import sass from 'gulp-sass';
import autoprefixer from 'gulp-autoprefixer';
import sourcemaps from 'gulp-sourcemaps';
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
gulp.task('styles', () => {
return gulp.src('src/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(autoprefixer())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/css'));
});
gulp.task('combine-js', () => {
return gulp.src('src/js/**/*.js')
.pipe(concat('script.js'))
.pipe(uglify())
.pipe(gulp.dest(dist + 'dist/js'));
});
gulp.task('default', ['styles', 'combine-js']);
4 . 6
Problem
5 . 1
5 . 2
gulp-handlebars
Latest commit on 14 Mar 2015
handlebars 3.0.0
5 . 3
handlebars
Latest commit on 10 Sep 2016
handlebars 4.0.5
5 . 4
5,900
Module Counts
2,600 333,000
< <
5 . 5
1. Is the base tool broken?
2. Is the Grunt/Gulp plugin broken?
3. Is the my configuration broken?
4. Am I using incompatible version?
Frustrating Debugging
5 . 6
Use npm module directly.
Without Grunt/Gulp.
Without Grunt/Gulp plugin.
Use npm scripts.
Solution
5 . 7
What is the npm scripts?
6 . 1
You already use
npm scripts
6 . 2
npm init
npm install
npm test
6 . 3
npm supports the
"scripts"
property of the
package.json scripts
6 . 4
{
"scripts": {
"test": "karma start",
"postinstall": "bower install"
}
}
npm test
npm install
package.json
usage
6 . 5
npm-scripts
publish, install, uninstall, version, test, stop, start
npm run-script
pre and post with matching will be run
(e.g. premyscript, myscript, postmyscript)
6 . 6
"scripts": {
"start": "npm run dev-server",
"dev-server": "webpack-dev-server"
}
npm dev-server
npm start
package.json
usage
npm start
6 . 7
{
"scripts": {
"test": "karma start",
"pretest": "npm run lint",
"posttest": "npm run build",
"postinstall": "bower install"
}
}
npm test
npm install
package.json
usage
Pre & Post scripts
6 . 8
{
"scripts": {
"lint": "eslint src/js",
"uglify": "uglifyjs src/js/*.js -m -o dist/js/app.js",
"build:js": "npm run lint && npm run uglify"
}
}
npm run lint
npm run uglify
npm run build:js
package.json
usage
npm run
6 . 9
npm run
shell's pre-existing PATH, npm run adds
node_modules/.bin to the PATH provided
to scripts.
{
"scripts": {
"test": "node_modules/.bin/karma start"
}
}
{
"scripts": {
"test": "karma start"
}
}
X O
6 . 10
Why npm scripts?
7 . 1
Cross-platform
Chaining tasks
Piping tasks
Concurrently tasks
Pre and Post Scripts
Sub-tasks
npm scripts can:
7 . 2
7 . 3
7 . 4
var gulp = require('gulp'),
webserver = require('gulp-webserver'),
del = require('del'),
sass = require('gulp-sass'),
karma = require('gulp-karma'),
jshint = require('gulp-jshint'),
sourcemaps = require('gulp-sourcemaps'),
spritesmith = require('gulp.spritesmith'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
uglify = require('gulp-uglify'),
gutil = require('gulp-util'),
ngAnnotate = require('browserify-ngannotate');
var CacheBuster = require('gulp-cachebust');
var cachebust = new CacheBuster();
/////////////////////////////////////////////////////////////////////////////////////
//
// cleans the build output
//
/////////////////////////////////////////////////////////////////////////////////////
gulp.task('clean', function (cb) {
del([
'dist'
], cb);
});
/////////////////////////////////////////////////////////////////////////////////////
//
angularjs with gulp
7 . 5
angularjs with gulp
integration with bower
Sass (with source maps)
unit testing / integration testing with Karma, Jasmine and PhantomJs
cache busting - to prevent cache problems in all environments, dev
tools opened or closed, etc.
template cache pre-population - to prevent that each template causes
one extra HTTP request
jshint - the de-facto Javascript code quality checker
concatenation
browserify integration - for using the CommonJs require('module')
synchronous import syntax and avoid maintaining config files with
dependencies
Javascript source maps
Angular-friendly Javascript minification
sprite generation
a development web server with live reload, that re-loads the initial
page of the project
7 . 6
{
"scripts": {
"clean": "rimraf dist/ && mkdirp dist/{js,css,html} && copyfiles favicon.ico dist",
"autoprefixer": "postcss -u autoprefixer -r dist/css/*.css",
"scss": "node-sass --output-style expanded --source-map=true -o dist/css src/scss",
"prebuild": "npm run clean && npm test",
"build:js": "browserify src/js/app.jsx --standalone app --transform babelify --debug -p [minify
"build:css": "npm run scss && postcss -u autoprefixer -r < dist/css/app.css | postcss -u cssnan
"build:html": "jade src/jade/index.jade --pretty --out dist/html/",
"build": "npm-run-all --sequential build:*",
"predev": "npm run clean",
"dev:js": "browserify src/js/app.jsx --standalone app --transform babelify --debug | hashmark -
"postdev:js": "jade src/jade/index.jade --pretty --obj dist/assets.json --out dist/html/",
"dev:css": "npm run scss && npm run autoprefixer && hashmark -s -l 8 -m dist/assets.json dist/c
"postdev:css": "jade src/jade/index.jade --pretty --obj dist/assets.json --out dist/html/",
"dev": "npm run dev:js && npm run dev:css",
"open": "opener http://localhost:9090/html/#/",
"live-reload": "live-reload --port 9091 dist/html/",
"serve": "http-server -p 9090 dist/",
"watch:css": "onchange "src/scss" -- npm run dev:css",
"watch:js": "onchange "src/js" -- npm run dev:js",
"watch": "npm-run-all --parallel watch:*",
"start": "npm run live-reload & npm run open && npm run serve & npm run watch",
"pretest": "eslint src/js test --ext=jsx --ext=js",
"test:debug": "karma start karma-debug.conf.js",
"test": "karma start"
react with npm scripts
7 . 7
react with npm scripts
Sass (with source maps)
unit testing / integration testing with Karma, Jasmine and PhantomJs
cache busting - to prevent cache problems in all environments, dev
tools opened or closed, etc.
jade template
eslint - Pluggable JavaScript linter
concatenation
browserify integration - for using the CommonJs require('module')
synchronous import syntax and avoid maintaining config files with
dependencies
Javascript source maps
React-friendly Javascript minification
JSX compile
a development web server with live reload, that re-loads the initial
page of the project
7 . 8
var gulp = require('gulp'),
webserver = require('gulp-webserver'),
del = require('del'),
sass = require('gulp-sass'),
karma = require('gulp-karma'),
jshint = require('gulp-jshint'),
sourcemaps = require('gulp-sourcemaps'),
spritesmith = require('gulp.spritesmith'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
uglify = require('gulp-uglify'),
gutil = require('gulp-util'),
ngAnnotate = require('browserify-ngannotate');
var CacheBuster = require('gulp-cachebust');
var cachebust = new CacheBuster();
gulp.task('clean', function (cb) {
del([
'dist'
], cb);
});
gulp.task('bower', function() {
var install = require("gulp-install");
return gulp.src(['./bower.json'])
.pipe(install());
});
gulp.task('build-css', ['clean'], function() {
return gulp.src('./styles/*')
.pipe(sourcemaps.init())
{
"scripts": {
"clean": "rimraf dist/ && mkdirp dist/{js,css,
"autoprefixer": "postcss -u autoprefixer -r di
"scss": "node-sass --output-style expanded --s
"prebuild": "npm run clean && npm test",
"build:js": "browserify src/js/app.jsx --stand
"build:css": "npm run scss && postcss -u autop
"build:html": "jade src/jade/index.jade --pret
"build": "npm-run-all --sequential build:*",
"predev": "npm run clean",
"dev:js": "browserify src/js/app.jsx --standal
"postdev:js": "jade src/jade/index.jade --pret
"dev:css": "npm run scss && npm run autoprefix
"postdev:css": "jade src/jade/index.jade --pre
"dev": "npm run dev:js && npm run dev:css",
"open": "opener http://localhost:9090/html/#/"
"live-reload": "live-reload --port 9091 dist/h
"serve": "http-server -p 9090 dist/",
"watch:css": "onchange "src/scss" -- npm run
"watch:js": "onchange "src/js" -- npm run de
"watch": "npm-run-all --parallel watch:*",
"start": "npm run live-reload & npm run open &
"pretest": "eslint src/js test --ext=jsx --ext
"test:debug": "karma start karma-debug.conf.js
"test": "karma start"
}
}
7 . 9
bash / node
cat / catw
mkdir / mkdirp
rm / rimraf
& / npm-run-all --parallel
Cross-platform
7 . 10
Chaning tasks(&&)
Running command is to run a command only
if the previous command is successful.
"scripts": {
...
"clean": "rimraf dist/ && mkdirp dist/{js,css,html} && copyfiles favicon.ico dist",
...
}
7 . 11
Concurrently tasks(&)
Sometimes it is also nice to be able to run
multiple commands at the concurrently.
"scripts": {
...
"watch": "npm run watch-js & npm run watch-less & npm run watch-jade",
...
},
7 . 12
Piping tasks(|)
piping (|) the output from browserify into uglifyjs.
"scripts": {
"build-js": "browserify -t reactify app/js/main.js | uglifyjs -mc > static/bundle.js"
}
7 . 13
{
"scripts": {
"test": "karma start",
"pretest": "npm run lint",
"posttest": "npm run build",
"postinstall": "bower install"
}
}
npm test
npm install
package.json
usage
Pre & Post scripts
7 . 14
"scripts": {
"lint": "eslint src/**/*.js",
"unit": "karma start",
"test": "npm run lint & npm run unit"
}
npm run lint
npm run unit
npm run test
package.json
usage
Sub-tasks
7 . 15
"scripts": {
"lint": "eslint src/**/*.js",
"unit": "karma start",
"test": "npm-run-all --sequential lint unit"
}
npm run test
package.json
usage
Sub-tasks
with npm-run-all
7 . 16
"scripts": {
"test:lint": "eslint src/**/*.js",
"test:unit": "karma start",
"test": "npm-run-all test:*"
}
npm run test
package.json
usage
Sub-tasks
with namespace
7 . 17
npm-build-boilerplate
"scripts": {
"clean": "rm -f dist/{css/*,js/*,images/*}",
"autoprefixer": "postcss -u autoprefixer -r dist/css/*",
"scss": "node-sass --output-style compressed -o dist/css src/scss",
"lint": "eslint src/js",
"uglify": "mkdir -p dist/js && uglifyjs src/js/*.js -m -o dist/js/app.js &&
"imagemin": "imagemin src/images/* -o dist/images",
"icons": "svgo -f src/images/icons && mkdir -p dist/images && svg-sprite-gen
"serve": "browser-sync start --server --files "dist/css/*.css, dist/js/*.js
"build:css": "npm run scss && npm run autoprefixer",
"build:js": "npm run lint && npm run uglify",
"build:images": "npm run imagemin && npm run icons",
"build:all": "npm run build:css && npm run build:js && npm run build:images"
"watch:css": "onchange "src/scss" -- npm run build:css",
"watch:js": "onchange "src/js" -- npm run build:js",
"watch:images": "onchange "src/images" -- npm run build:images",
"watch:all": "npm-run-all -p serve watch:css watch:js watch:images",
"postinstall": "npm run build:all && npm run watch:all"
}
7 . 18
npm-react-todomvc
"scripts": {
"clean": "rimraf dist/ && mkdirp dist/{js,css,html} && copyfiles favicon.ico
"autoprefixer": "postcss -u autoprefixer -r dist/css/*.css",
"scss": "node-sass --output-style expanded --source-map=true -o dist/css src
"prebuild": "npm run clean && npm test",
"build:js": "browserify src/js/app.jsx --standalone app --transform babelify
"build:css": "npm run scss && postcss -u autoprefixer -r < dist/css/app.css
"build:html": "jade src/jade/index.jade --pretty --out dist/html/",
"build": "npm-run-all --sequential build:*",
"predev": "npm run clean",
"dev:js": "browserify src/js/app.jsx --standalone app --transform babelify -
"postdev:js": "jade src/jade/index.jade --pretty --obj dist/assets.json --ou
"dev:css": "npm run scss && npm run autoprefixer && hashmark -s -l 8 -m dist
"postdev:css": "jade src/jade/index.jade --pretty --obj dist/assets.json --o
"dev": "npm run dev:js && npm run dev:css",
"open": "opener http://localhost:9090/html/#/",
"live-reload": "live-reload --port 9091 dist/html/",
"serve": "http-server -p 9090 dist/",
"watch:css": "onchange "src/scss" -- npm run dev:css", 7 . 19
7 . 20
npm script
+
webpack
=
Best Build Tool
7 . 21
THANK YOU??
7 . 22
8 . 1
8 . 2
yarn vs npm install
8 . 3
8 . 4
Prototype vs. jQuery
Backbone vs. Knockout
Angular vs. React
Grunt vs. Gulp
NPM vs. Yarn
8 . 5
8 . 6
npm script
+
webpack
=
Best Build Tool
8 . 7
Less code,
less extensible
8 . 8
Useful Link
Why I Left Gulp and Grunt for npm Scripts
Why npm Scripts?
How to Use npm as a Build Tool
Advanced front-end automation
with npm scripts
8 . 9
Sample
npm-react-todomvc
8 . 10
THANK YOU!
8 . 11

More Related Content

What's hot

Javascript Bundling and modularization
Javascript Bundling and modularizationJavascript Bundling and modularization
Javascript Bundling and modularizationstbaechler
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end WorkflowPagepro
 
Magento 2 Capistrano Deploy
Magento 2 Capistrano DeployMagento 2 Capistrano Deploy
Magento 2 Capistrano DeployDuke Dao
 
Bower - A package manager for the web
Bower - A package manager for the webBower - A package manager for the web
Bower - A package manager for the webLarry Nung
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspmJesse Warden
 
Production Ready Javascript With Grunt
Production Ready Javascript With GruntProduction Ready Javascript With Grunt
Production Ready Javascript With GruntXB Software, Ltd.
 
Introduction to using Grunt & Bower with WordPress theme development
Introduction to using Grunt & Bower with WordPress theme developmentIntroduction to using Grunt & Bower with WordPress theme development
Introduction to using Grunt & Bower with WordPress theme developmentJames Bundey
 
Frontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeFrontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeDamien Seguin
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS偉格 高
 
Modernizing Your WordPress Workflow with Grunt & Bower
Modernizing Your WordPress Workflow with Grunt & BowerModernizing Your WordPress Workflow with Grunt & Bower
Modernizing Your WordPress Workflow with Grunt & BowerAlan Crissey
 
네이버 오픈세미나 백엔드_아키텍쳐
네이버 오픈세미나 백엔드_아키텍쳐네이버 오픈세미나 백엔드_아키텍쳐
네이버 오픈세미나 백엔드_아키텍쳐NAVER D2
 
NLIT 2011: Chef & Capistrano
NLIT 2011: Chef & CapistranoNLIT 2011: Chef & Capistrano
NLIT 2011: Chef & Capistranonickblah
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIBrian Hogg
 
Preprocessor Workflow with Grunt
Preprocessor Workflow with GruntPreprocessor Workflow with Grunt
Preprocessor Workflow with GruntVlad Filippov
 
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With ContainersHanoi MagentoMeetup
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Derek Willian Stavis
 

What's hot (20)

Javascript Bundling and modularization
Javascript Bundling and modularizationJavascript Bundling and modularization
Javascript Bundling and modularization
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
 
Magento 2 Capistrano Deploy
Magento 2 Capistrano DeployMagento 2 Capistrano Deploy
Magento 2 Capistrano Deploy
 
Bower - A package manager for the web
Bower - A package manager for the webBower - A package manager for the web
Bower - A package manager for the web
 
System webpack-jspm
System webpack-jspmSystem webpack-jspm
System webpack-jspm
 
Production Ready Javascript With Grunt
Production Ready Javascript With GruntProduction Ready Javascript With Grunt
Production Ready Javascript With Grunt
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
Introduction to using Grunt & Bower with WordPress theme development
Introduction to using Grunt & Bower with WordPress theme developmentIntroduction to using Grunt & Bower with WordPress theme development
Introduction to using Grunt & Bower with WordPress theme development
 
Frontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the likeFrontend JS workflow - Gulp 4 and the like
Frontend JS workflow - Gulp 4 and the like
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 
Modernizing Your WordPress Workflow with Grunt & Bower
Modernizing Your WordPress Workflow with Grunt & BowerModernizing Your WordPress Workflow with Grunt & Bower
Modernizing Your WordPress Workflow with Grunt & Bower
 
Webpack DevTalk
Webpack DevTalkWebpack DevTalk
Webpack DevTalk
 
Node js
Node jsNode js
Node js
 
네이버 오픈세미나 백엔드_아키텍쳐
네이버 오픈세미나 백엔드_아키텍쳐네이버 오픈세미나 백엔드_아키텍쳐
네이버 오픈세미나 백엔드_아키텍쳐
 
NLIT 2011: Chef & Capistrano
NLIT 2011: Chef & CapistranoNLIT 2011: Chef & Capistrano
NLIT 2011: Chef & Capistrano
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
 
Preprocessor Workflow with Grunt
Preprocessor Workflow with GruntPreprocessor Workflow with Grunt
Preprocessor Workflow with Grunt
 
Webpack: from 0 to 2
Webpack: from 0 to 2Webpack: from 0 to 2
Webpack: from 0 to 2
 
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
 

Viewers also liked

Yarn package management
Yarn package managementYarn package management
Yarn package managementrudiyardley
 
Использовании TypeScript для Node.js
Использовании TypeScript для Node.jsИспользовании TypeScript для Node.js
Использовании TypeScript для Node.jsFullStackJS
 
Yarn – der neue Package Manager von Facebook
Yarn – der neue Package Manager von FacebookYarn – der neue Package Manager von Facebook
Yarn – der neue Package Manager von FacebookPOINT. Consulting GmbH
 
Startup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JSStartup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JSCirculus
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseAaron Silverman
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
Harnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache TwillHarnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache TwillTerence Yim
 
프론트엔드 개발자의 자바스크립트
프론트엔드 개발자의 자바스크립트 프론트엔드 개발자의 자바스크립트
프론트엔드 개발자의 자바스크립트 jeong seok yang
 
Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나JeongHun Byeon
 

Viewers also liked (13)

Yarn package management
Yarn package managementYarn package management
Yarn package management
 
Использовании TypeScript для Node.js
Использовании TypeScript для Node.jsИспользовании TypeScript для Node.js
Использовании TypeScript для Node.js
 
Yarn
YarnYarn
Yarn
 
Nodeconf npm 2011
Nodeconf npm 2011Nodeconf npm 2011
Nodeconf npm 2011
 
Jaap : node, npm & grunt
Jaap : node, npm & gruntJaap : node, npm & grunt
Jaap : node, npm & grunt
 
Yarn – der neue Package Manager von Facebook
Yarn – der neue Package Manager von FacebookYarn – der neue Package Manager von Facebook
Yarn – der neue Package Manager von Facebook
 
Startup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JSStartup JavaScript 8 - NPM, Express.JS
Startup JavaScript 8 - NPM, Express.JS
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Harnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache TwillHarnessing the power of YARN with Apache Twill
Harnessing the power of YARN with Apache Twill
 
프론트엔드 개발자의 자바스크립트
프론트엔드 개발자의 자바스크립트 프론트엔드 개발자의 자바스크립트
프론트엔드 개발자의 자바스크립트
 
Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나Front-end Development Process - 어디까지 개선할 수 있나
Front-end Development Process - 어디까지 개선할 수 있나
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
 

Similar to Use NPM scripts for automation and build workflows

(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of usStefan Adolf
 
Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)Future Insights
 
A few good JavaScript development tools
A few good JavaScript development toolsA few good JavaScript development tools
A few good JavaScript development toolsSimon Kim
 
Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usWebpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usStefan Adolf
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und buildDaniel Fisher
 
Automating Front-End Workflow
Automating Front-End WorkflowAutomating Front-End Workflow
Automating Front-End WorkflowDimitris Tsironis
 
Javascript is your (Auto)mate
Javascript is your (Auto)mateJavascript is your (Auto)mate
Javascript is your (Auto)mateCodemotion
 
Web development tools { starter pack }
Web development tools { starter pack }Web development tools { starter pack }
Web development tools { starter pack }François Michaudon
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36Halil Kaya
 
May The Nodejs Be With You
May The Nodejs Be With YouMay The Nodejs Be With You
May The Nodejs Be With YouDalibor Gogic
 
JS digest. February 2017
JS digest. February 2017JS digest. February 2017
JS digest. February 2017ElifTech
 
Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Fwdays
 
Workflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.jsWorkflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.jsDavidson Fellipe
 
Quest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFREDQuest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFREDAndi Smith
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesLindsay Holmwood
 
Server Side Apocalypse, JS
Server Side Apocalypse, JSServer Side Apocalypse, JS
Server Side Apocalypse, JSMd. Sohel Rana
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular applicationmirrec
 

Similar to Use NPM scripts for automation and build workflows (20)

(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us
 
Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)
 
A few good JavaScript development tools
A few good JavaScript development toolsA few good JavaScript development tools
A few good JavaScript development tools
 
Webpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of usWebpack Encore - Asset Management for the rest of us
Webpack Encore - Asset Management for the rest of us
 
2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build2015 - Basta! 2015, DE: JavaScript und build
2015 - Basta! 2015, DE: JavaScript und build
 
Automating Front-End Workflow
Automating Front-End WorkflowAutomating Front-End Workflow
Automating Front-End Workflow
 
Javascript is your (Auto)mate
Javascript is your (Auto)mateJavascript is your (Auto)mate
Javascript is your (Auto)mate
 
Web development tools { starter pack }
Web development tools { starter pack }Web development tools { starter pack }
Web development tools { starter pack }
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
 
Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36
 
May The Nodejs Be With You
May The Nodejs Be With YouMay The Nodejs Be With You
May The Nodejs Be With You
 
JS digest. February 2017
JS digest. February 2017JS digest. February 2017
JS digest. February 2017
 
Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"
 
Workflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.jsWorkflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.js
 
Quest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFREDQuest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFRED
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Server Side Apocalypse, JS
Server Side Apocalypse, JSServer Side Apocalypse, JS
Server Side Apocalypse, JS
 
GruntJS + Wordpress
GruntJS + WordpressGruntJS + Wordpress
GruntJS + Wordpress
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 

Recently uploaded

KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosVictor Morales
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdfsahilsajad201
 
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdfDEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdfAkritiPradhan2
 
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSneha Padhiar
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solidnamansinghjarodiya
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Sumanth A
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.elesangwon
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdfCaalaaAbdulkerim
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdfPaper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdfNainaShrivastava14
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfDrew Moseley
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书rnrncn29
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHSneha Padhiar
 
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...Stork
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsResearcher Researcher
 

Recently uploaded (20)

KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitos
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdf
 
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdfDEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
 
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solid
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
2022 AWS DNA Hackathon 장애 대응 솔루션 jarvis.
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdf
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdfPaper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
Paper Tube : Shigeru Ban projects and Case Study of Cardboard Cathedral .pdf
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdf
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
 
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending Actuators
 

Use NPM scripts for automation and build workflows

  • 1. Introduction to Using NPM scripts as a Build Tool. /@kjy2143 SK planet 1 . 1
  • 9. 2016/2017 MUST-KNOW WEB DEVELOPMENT TECH CSS Preprocessor Compile ES2016+ Compile Optimization Linting Unit Testing Module Bundling Package Management 3 . 3
  • 13. JavaScript Uglify npm install uglify-js -g uglifyjs foo.js -o foo.min.js 3 . 7
  • 14. JavaScript Linting npm install jshint -g npm install jshint-stylish --save-dev jshint --reporter=node_modules/jshint-stylish foo.js 3 . 8
  • 15. Command Line Interface CSS Preprocessor Compile ES2016+ Compile Optimization Linting Unit Testing Module Bundling Package Management 3 . 9
  • 18. Gruntfile.js module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") % }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } }); // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); // Default task(s). grunt.registerTask('default', ['uglify']); }; 4 . 3
  • 20. Automate and enhance your workflow 4 . 5
  • 21. gulpfile.babel.js import gulp from 'gulp'; import sass from 'gulp-sass'; import autoprefixer from 'gulp-autoprefixer'; import sourcemaps from 'gulp-sourcemaps'; import concat from 'gulp-concat'; import uglify from 'gulp-uglify'; gulp.task('styles', () => { return gulp.src('src/sass/**/*.scss') .pipe(sourcemaps.init()) .pipe(autoprefixer()) .pipe(sourcemaps.write('.')) .pipe(gulp.dest('dist/css')); }); gulp.task('combine-js', () => { return gulp.src('src/js/**/*.js') .pipe(concat('script.js')) .pipe(uglify()) .pipe(gulp.dest(dist + 'dist/js')); }); gulp.task('default', ['styles', 'combine-js']); 4 . 6
  • 23. 5 . 2
  • 24. gulp-handlebars Latest commit on 14 Mar 2015 handlebars 3.0.0 5 . 3
  • 25. handlebars Latest commit on 10 Sep 2016 handlebars 4.0.5 5 . 4
  • 27. 1. Is the base tool broken? 2. Is the Grunt/Gulp plugin broken? 3. Is the my configuration broken? 4. Am I using incompatible version? Frustrating Debugging 5 . 6
  • 28. Use npm module directly. Without Grunt/Gulp. Without Grunt/Gulp plugin. Use npm scripts. Solution 5 . 7
  • 29. What is the npm scripts? 6 . 1
  • 30. You already use npm scripts 6 . 2
  • 32. npm supports the "scripts" property of the package.json scripts 6 . 4
  • 33. { "scripts": { "test": "karma start", "postinstall": "bower install" } } npm test npm install package.json usage 6 . 5
  • 34. npm-scripts publish, install, uninstall, version, test, stop, start npm run-script pre and post with matching will be run (e.g. premyscript, myscript, postmyscript) 6 . 6
  • 35. "scripts": { "start": "npm run dev-server", "dev-server": "webpack-dev-server" } npm dev-server npm start package.json usage npm start 6 . 7
  • 36. { "scripts": { "test": "karma start", "pretest": "npm run lint", "posttest": "npm run build", "postinstall": "bower install" } } npm test npm install package.json usage Pre & Post scripts 6 . 8
  • 37. { "scripts": { "lint": "eslint src/js", "uglify": "uglifyjs src/js/*.js -m -o dist/js/app.js", "build:js": "npm run lint && npm run uglify" } } npm run lint npm run uglify npm run build:js package.json usage npm run 6 . 9
  • 38. npm run shell's pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts. { "scripts": { "test": "node_modules/.bin/karma start" } } { "scripts": { "test": "karma start" } } X O 6 . 10
  • 40. Cross-platform Chaining tasks Piping tasks Concurrently tasks Pre and Post Scripts Sub-tasks npm scripts can: 7 . 2
  • 41. 7 . 3
  • 42. 7 . 4
  • 43. var gulp = require('gulp'), webserver = require('gulp-webserver'), del = require('del'), sass = require('gulp-sass'), karma = require('gulp-karma'), jshint = require('gulp-jshint'), sourcemaps = require('gulp-sourcemaps'), spritesmith = require('gulp.spritesmith'), browserify = require('browserify'), source = require('vinyl-source-stream'), buffer = require('vinyl-buffer'), uglify = require('gulp-uglify'), gutil = require('gulp-util'), ngAnnotate = require('browserify-ngannotate'); var CacheBuster = require('gulp-cachebust'); var cachebust = new CacheBuster(); ///////////////////////////////////////////////////////////////////////////////////// // // cleans the build output // ///////////////////////////////////////////////////////////////////////////////////// gulp.task('clean', function (cb) { del([ 'dist' ], cb); }); ///////////////////////////////////////////////////////////////////////////////////// // angularjs with gulp 7 . 5
  • 44. angularjs with gulp integration with bower Sass (with source maps) unit testing / integration testing with Karma, Jasmine and PhantomJs cache busting - to prevent cache problems in all environments, dev tools opened or closed, etc. template cache pre-population - to prevent that each template causes one extra HTTP request jshint - the de-facto Javascript code quality checker concatenation browserify integration - for using the CommonJs require('module') synchronous import syntax and avoid maintaining config files with dependencies Javascript source maps Angular-friendly Javascript minification sprite generation a development web server with live reload, that re-loads the initial page of the project 7 . 6
  • 45. { "scripts": { "clean": "rimraf dist/ && mkdirp dist/{js,css,html} && copyfiles favicon.ico dist", "autoprefixer": "postcss -u autoprefixer -r dist/css/*.css", "scss": "node-sass --output-style expanded --source-map=true -o dist/css src/scss", "prebuild": "npm run clean && npm test", "build:js": "browserify src/js/app.jsx --standalone app --transform babelify --debug -p [minify "build:css": "npm run scss && postcss -u autoprefixer -r < dist/css/app.css | postcss -u cssnan "build:html": "jade src/jade/index.jade --pretty --out dist/html/", "build": "npm-run-all --sequential build:*", "predev": "npm run clean", "dev:js": "browserify src/js/app.jsx --standalone app --transform babelify --debug | hashmark - "postdev:js": "jade src/jade/index.jade --pretty --obj dist/assets.json --out dist/html/", "dev:css": "npm run scss && npm run autoprefixer && hashmark -s -l 8 -m dist/assets.json dist/c "postdev:css": "jade src/jade/index.jade --pretty --obj dist/assets.json --out dist/html/", "dev": "npm run dev:js && npm run dev:css", "open": "opener http://localhost:9090/html/#/", "live-reload": "live-reload --port 9091 dist/html/", "serve": "http-server -p 9090 dist/", "watch:css": "onchange "src/scss" -- npm run dev:css", "watch:js": "onchange "src/js" -- npm run dev:js", "watch": "npm-run-all --parallel watch:*", "start": "npm run live-reload & npm run open && npm run serve & npm run watch", "pretest": "eslint src/js test --ext=jsx --ext=js", "test:debug": "karma start karma-debug.conf.js", "test": "karma start" react with npm scripts 7 . 7
  • 46. react with npm scripts Sass (with source maps) unit testing / integration testing with Karma, Jasmine and PhantomJs cache busting - to prevent cache problems in all environments, dev tools opened or closed, etc. jade template eslint - Pluggable JavaScript linter concatenation browserify integration - for using the CommonJs require('module') synchronous import syntax and avoid maintaining config files with dependencies Javascript source maps React-friendly Javascript minification JSX compile a development web server with live reload, that re-loads the initial page of the project 7 . 8
  • 47. var gulp = require('gulp'), webserver = require('gulp-webserver'), del = require('del'), sass = require('gulp-sass'), karma = require('gulp-karma'), jshint = require('gulp-jshint'), sourcemaps = require('gulp-sourcemaps'), spritesmith = require('gulp.spritesmith'), browserify = require('browserify'), source = require('vinyl-source-stream'), buffer = require('vinyl-buffer'), uglify = require('gulp-uglify'), gutil = require('gulp-util'), ngAnnotate = require('browserify-ngannotate'); var CacheBuster = require('gulp-cachebust'); var cachebust = new CacheBuster(); gulp.task('clean', function (cb) { del([ 'dist' ], cb); }); gulp.task('bower', function() { var install = require("gulp-install"); return gulp.src(['./bower.json']) .pipe(install()); }); gulp.task('build-css', ['clean'], function() { return gulp.src('./styles/*') .pipe(sourcemaps.init()) { "scripts": { "clean": "rimraf dist/ && mkdirp dist/{js,css, "autoprefixer": "postcss -u autoprefixer -r di "scss": "node-sass --output-style expanded --s "prebuild": "npm run clean && npm test", "build:js": "browserify src/js/app.jsx --stand "build:css": "npm run scss && postcss -u autop "build:html": "jade src/jade/index.jade --pret "build": "npm-run-all --sequential build:*", "predev": "npm run clean", "dev:js": "browserify src/js/app.jsx --standal "postdev:js": "jade src/jade/index.jade --pret "dev:css": "npm run scss && npm run autoprefix "postdev:css": "jade src/jade/index.jade --pre "dev": "npm run dev:js && npm run dev:css", "open": "opener http://localhost:9090/html/#/" "live-reload": "live-reload --port 9091 dist/h "serve": "http-server -p 9090 dist/", "watch:css": "onchange "src/scss" -- npm run "watch:js": "onchange "src/js" -- npm run de "watch": "npm-run-all --parallel watch:*", "start": "npm run live-reload & npm run open & "pretest": "eslint src/js test --ext=jsx --ext "test:debug": "karma start karma-debug.conf.js "test": "karma start" } } 7 . 9
  • 48. bash / node cat / catw mkdir / mkdirp rm / rimraf & / npm-run-all --parallel Cross-platform 7 . 10
  • 49. Chaning tasks(&&) Running command is to run a command only if the previous command is successful. "scripts": { ... "clean": "rimraf dist/ && mkdirp dist/{js,css,html} && copyfiles favicon.ico dist", ... } 7 . 11
  • 50. Concurrently tasks(&) Sometimes it is also nice to be able to run multiple commands at the concurrently. "scripts": { ... "watch": "npm run watch-js & npm run watch-less & npm run watch-jade", ... }, 7 . 12
  • 51. Piping tasks(|) piping (|) the output from browserify into uglifyjs. "scripts": { "build-js": "browserify -t reactify app/js/main.js | uglifyjs -mc > static/bundle.js" } 7 . 13
  • 52. { "scripts": { "test": "karma start", "pretest": "npm run lint", "posttest": "npm run build", "postinstall": "bower install" } } npm test npm install package.json usage Pre & Post scripts 7 . 14
  • 53. "scripts": { "lint": "eslint src/**/*.js", "unit": "karma start", "test": "npm run lint & npm run unit" } npm run lint npm run unit npm run test package.json usage Sub-tasks 7 . 15
  • 54. "scripts": { "lint": "eslint src/**/*.js", "unit": "karma start", "test": "npm-run-all --sequential lint unit" } npm run test package.json usage Sub-tasks with npm-run-all 7 . 16
  • 55. "scripts": { "test:lint": "eslint src/**/*.js", "test:unit": "karma start", "test": "npm-run-all test:*" } npm run test package.json usage Sub-tasks with namespace 7 . 17
  • 56. npm-build-boilerplate "scripts": { "clean": "rm -f dist/{css/*,js/*,images/*}", "autoprefixer": "postcss -u autoprefixer -r dist/css/*", "scss": "node-sass --output-style compressed -o dist/css src/scss", "lint": "eslint src/js", "uglify": "mkdir -p dist/js && uglifyjs src/js/*.js -m -o dist/js/app.js && "imagemin": "imagemin src/images/* -o dist/images", "icons": "svgo -f src/images/icons && mkdir -p dist/images && svg-sprite-gen "serve": "browser-sync start --server --files "dist/css/*.css, dist/js/*.js "build:css": "npm run scss && npm run autoprefixer", "build:js": "npm run lint && npm run uglify", "build:images": "npm run imagemin && npm run icons", "build:all": "npm run build:css && npm run build:js && npm run build:images" "watch:css": "onchange "src/scss" -- npm run build:css", "watch:js": "onchange "src/js" -- npm run build:js", "watch:images": "onchange "src/images" -- npm run build:images", "watch:all": "npm-run-all -p serve watch:css watch:js watch:images", "postinstall": "npm run build:all && npm run watch:all" } 7 . 18
  • 57. npm-react-todomvc "scripts": { "clean": "rimraf dist/ && mkdirp dist/{js,css,html} && copyfiles favicon.ico "autoprefixer": "postcss -u autoprefixer -r dist/css/*.css", "scss": "node-sass --output-style expanded --source-map=true -o dist/css src "prebuild": "npm run clean && npm test", "build:js": "browserify src/js/app.jsx --standalone app --transform babelify "build:css": "npm run scss && postcss -u autoprefixer -r < dist/css/app.css "build:html": "jade src/jade/index.jade --pretty --out dist/html/", "build": "npm-run-all --sequential build:*", "predev": "npm run clean", "dev:js": "browserify src/js/app.jsx --standalone app --transform babelify - "postdev:js": "jade src/jade/index.jade --pretty --obj dist/assets.json --ou "dev:css": "npm run scss && npm run autoprefixer && hashmark -s -l 8 -m dist "postdev:css": "jade src/jade/index.jade --pretty --obj dist/assets.json --o "dev": "npm run dev:js && npm run dev:css", "open": "opener http://localhost:9090/html/#/", "live-reload": "live-reload --port 9091 dist/html/", "serve": "http-server -p 9090 dist/", "watch:css": "onchange "src/scss" -- npm run dev:css", 7 . 19
  • 61. 8 . 1
  • 62. 8 . 2
  • 63. yarn vs npm install 8 . 3
  • 64. 8 . 4
  • 65. Prototype vs. jQuery Backbone vs. Knockout Angular vs. React Grunt vs. Gulp NPM vs. Yarn 8 . 5
  • 66. 8 . 6
  • 69. Useful Link Why I Left Gulp and Grunt for npm Scripts Why npm Scripts? How to Use npm as a Build Tool Advanced front-end automation with npm scripts 8 . 9