BestACE / fed

旨为锤炼前端开发工程师的前端开发基础课程,重点学习利用html和css实现页面布局,利用JS实现交互开发。:thumbsup:
208 stars 137 forks source link

【资源帖】Gulp入门指南 #439

Open whqet opened 6 years ago

whqet commented 6 years ago
  1. 需要安装node.js运行环境,没有下载可以到官方下载
  2. 安装gulp.js,步骤参考官方网站新版
  3. cnpm使用,使用淘宝的npm镜像
zptcsoft commented 6 years ago

上课的时候用到的package.json

{
  "name": "web",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0",
    "gulp": "^3.9.1",
    "gulp-babel": "^7.0.1",
    "gulp-uglify": "^3.0.1",
    "pump": "^3.0.0"
  }
}
zptcsoft commented 6 years ago

上课时用到的gulpfile.js

const gulp = require('gulp');
const uglify = require('gulp-uglify');
const babel = require('gulp-babel');
const pump = require('pump');

gulp.task('default',function(){
    console.log('ok');
})

gulp.task('compress', function (cb) {
  pump([
        gulp.src('js/*.js'),
        babel({
            "presets": ["env"]
        }),
        uglify(),
        gulp.dest('dist')
    ],
    cb
  );
});