基于gulp webpack ES6 node.js 构建项目

基于gulp webpack ES6 node.js

目录构建

  • 前端文件 app目录
    • 内含 css目录
    • js目录
      • index.js 以及class类目录
    • views目录
      • index.html
      • error.html
  • 服务端文件 server目录
    • 用express -e . 命令构建服务端脚手架
      注意:在使用express -e . 的命令时,cmd给我报了一段无法识别express command的错误,在网上查了一下,有人指出是express4的版本将命令工具分家了,所以需要我们安装以恶搞命令工具:
      命令如下:npm install -g express-generator
      之后再次安装:npm install -g express
      前提要全局安装node.js哦
    • npm install 加载项目依赖
  • 任务文件 tasks目录
    • 根目录文件 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-rename'
        import rename 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({
                errorHandler: 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()))
    })
  • 内含util目录 用于放置功能类脚本
    • 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 scripts'
          })
          .option('verbose', {
              boolean: true,
              default: false,
              describe: 'log'
          })
          .option('sourcemaps', {
              describe: 'force the creation of sourcemaps'
          })
          .option('port', {
              string: true,
              default: 8080,
              describe: 'server port'
          })
          //表示命令行以字符串作为解析
          .argv
      
  • 创建package.json文件
  • 创建 .babelrc 配置文件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值