Take Windows 10 as an example
premise
NodeJS has been installed and configured.
install
cmd enters the Windows command line window, enters the test directory, C: Develop gulptest, and executes under the test directory if no creation is required.
C:\Develop>mkdir gulptest C:\Develop>cd gulptest C:\Develop\gulptest>npm init This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults. See `npm help json` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg>` afterwards to install a package and save it as a dependency in the package.json file. Press ^C at any time to quit. package name: (gulptest) version: (1.0.0) description: entry point: (index.js) test command: git repository: keywords: author: license: (ISC) About to write to C:\Develop\gulptest\package.json: { "name": "gulptest", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" } Is this OK? (yes)
Next he will ask you to fill in some project information, which can be filled in later, so just go all the way back. He will generate a package.json file in the directory.
Global Installation gulp
C:\Develop\gulptest>npm install gulp-cli -g C:\Develop\gulptest>npm install gulp -g
Install Gulp into the project
Enter the following command to install gulp into the current project and tell the package.json that you used gulp
npm install gulp -D
Create gulpfile.js under the project root directory
Install plug-ins
npm install gulp-uglify -D
Write gulpfile.js
//Get the gulp just installed var gulp = require('gulp') //Get the gulp-uglify module just installed var uglify = require('gulp-uglify') //Compressing js files //Start this task at the command line using gulp uglifyscript gulp.task('uglifyscript', done => { // 1. Find the document gulp.src('src/js/*.js') // 2. Compressed files .pipe(uglify()) // 3. Save compressed files .pipe(gulp.dest('dist/js')) done() })