无标题文章

1.项目目录创建

image
image

2.使用express脚手架工具

cd server

express -e .

npm install

3.自动创建package.json文件

npm init

4.创建babel工具的配置文件

touch .babelrc

touch gulpfile.babel.js

5.编写任务脚本

args.js:

import yargs from 'yargs';

const args = yargs

.option('production',{
  boolean:true,
  default:false,
  describe:'min all scripts'
})

.option('watch',{
  boolean:true,
  default:false,
  describe:'watch all files'
})

.option('verbose',{
  boolean:true,
  default:false,
  describe:'log'
})

.option('sourcemaps',{
  describe:'force the creation of sroucemaps'
})

.option('port',{
  string:true,
  default:8080,
  describe:'server port'
})
  
  .argv;

export default args;

6.创建script脚本

scripts.js:

import gulp from 'gulp';
import gulpif from 'gulp-if';
import concat from 'gulp-concat';
import webpack from 'webpack';
import gulpWebpack from 'webpack-stream';
import named from 'vinyl-named';
import livereload from 'gulp-livereload';
import plumber from 'gulp-plumber';
import rename from 'gulp-rename';
import uglify from 'gulp-uglify';
import {log,colors} from 'gulp-util';
import args from './util/args';

gulp.task('scripts',()=>{
  return gulp.src(['app/js/index.js'])
  .pipe(plumber({
    errorHandle:function(){
      
    }
  }))
  .pipe(named())
  .pipe(gulpWebpack({
    module:{
      loaders:[{
        test:/\.js$/,
        loader:'babel'
      }]
    }
  }),null,(err,stats)=>{
    log(`Finished '${colors.cyan('scripts')}'`,stats.toString({
      chunks:false
    }))
  })
  .pipe(gulp.dest('server/public/js'))
  .pipe(rename({
    basename:'cp',
    extname:'.min.js'
  }))
  .pipe(uglify({compress:{properties:false},output:{'quote_keys':true}}))
  .pipe(gulp.dest('server/public/js'))
  .pipe(gulpif(args.watch,livereload()))
});
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • jHipster - 微服务搭建 CC_简书[https://www.jianshu.com/u/be0d56c4...
    quanjj阅读 4,243评论 0 2
  • webPack Webpack是目前比较流行的前端打包工具,它同时支持AMD、CMD两种模块写法,也原生支持npm...
    col128阅读 1,872评论 0 2
  • 清理 每天也不知道在忙碌些什么,忙得顾不上收拾家,家里的东西放到乱七八糟。用了这个东西,往往随手一放,下...
    青之心路阅读 1,423评论 0 0
  • 2017.08.13 第一次来北京,对这座城市的印象可能跟之前想象的不大一样,它有它的节奏,也有它的魅力。 初来乍...
    春天里的流浪汉阅读 4,902评论 0 1
  • 两天时间的培训课程,通过沙盘去系统化的感受了变革的过程。也在参与的过程中,感受到了不同职位、不同背景的管理者在看待...
    文文日阅读 1,521评论 0 1