Git Product home page Git Product logo

week-5's Introduction

Week 5: NPM and Gulp

Set up Gulp

we'll do this together

  1. Pull down this project
  2. Install gulp globally: npm install -g gulp #PATH
  3. Install gulp locally: npm install gulp
  4. Create a gulpfile.js in the root of this project
  5. Require Gulp: var gulp = require('gulp');
  6. Create a new task, call it "copy": gulp.task('copy', function(){ ... });
  7. Use gulp.src and pipe to gulp.dest to copy files from js/*.js to dist/
  • gulp.src('js/app/*.js')
  • .pipe(gulp.dest('dist/'));

Install and Set up a jshint

we'll do this together

  1. Install jshinter
  2. require the gulp-jshint module
  3. Create a new "jshint" task
  4. Use gulp.src to get the src files
  5. pipe that to jshint()
  6. pipe that to jshint.reporter()
  7. Install jshint-stylish
  8. Change the reporter to jshint.reporter('jshint-stylish')
  9. Add the new task to the default task
  10. Run gulp
  11. Fix the errors

Install and set up concatenation

do this on your own

  1. Install concatenator
  2. require the gulp-concat module
  3. Create a new "buildApp" task
  4. Use gulp.src to get the src files
  5. pipe that to concat(app.js)
  6. pipe that to gulp.dest ./dist
  7. Check out the app.js file
  8. Now that you have this new file, reference that instead of the app files in index.html

Install and Set up Uglification

do this on your own

  1. Install minifier
  2. require the gulp-uglify module
  3. Add the uglify() function to the buildApp pipes
  4. Check out the app.js file

Repeat for Vendor Files

on your own

  1. Create a "buildVendor" task
  2. concat and uglify the files found in there

Combine App and Vendor Builds

on your own

  1. Create a new "build" task `gulp.task('build', ['buildApp', 'buildVendor']);
  2. Add the build task to the default task

Install and set up karma

do this one on your own

  1. Install via npm: karma, karma-jasmine, karma-phantomjs-launcher locally
  2. Add a Server variable pointing to the karma dir: var Server = require('karma').server;
  3. Add the following task
gulp.task('karma', function (done) {
  new Server({
    configFile: __dirname + '/karma.conf.js',
    singleRun: true
  }, done).start();
});
  1. Remove the singleRun line if you want it to run with autowatch
  2. See this for more information

Combine jshint and karma

on your own

  1. Create a new task "test" that will call both the jshint task and the karma task

Install and set up a watch task

we'll do this together

  1. Create a new task called "watch"
  2. Use gulp.watch() to watch for changes to the js/app files and run "test" and "build" when changed
  3. Use it again to watch for changes to js/tests and run "test" when changed

week-5's People

Contributors

jazahn avatar dominickp avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.