晚上在Linux下搭建環境,代碼都下好了,gulp也在全局裝好了,按照在Windows下的習慣,直接在目錄下敲gulp,結果拋出異常了。css
開始還覺得是權限問題,用了sudo發現沒用,就去看了看gulpfile.js,內容以下:html
'use strict'; var gulp = require('gulp'); var g = require('gulp-load-plugins')({lazy: false}); var inject = require('gulp-inject'); var browserSync = require('browser-sync'); var connect = require('gulp-connect'); var historyApiFallback = require('connect-history-api-fallback'); var reload = browserSync.reload; var config = { paths: { html: { src: ["src/**/*.html"], dest: "build" }, js: { src: ["src/**/*.js",'!./src/lib/angular.min.js','!./src/lib/jquery.min.js','!./src/js/app.js'], dest: "build/js" }, css: { src: ["src/css/**/*.css"], dest: "build/css" }, assets: { src: ["src/assets/**/*.png", "src/assets/**/*.jpg"], dest: "build/assets" } } } //打包config var distConfig = { paths: { libjs: { src: ["src/lib/angular.min.js","src/lib/jquery.min.js","src/lib/angular-resource.min.js","src/lib/angular-ui-router.min.js","src/lib/highcharts-ng.js","src/lib/highcharts.js","src/lib/smart-table.min.js","src/lib/ui-bootstrap-tpls-0.13.2.min.js"], }, appjs: { src: ["src/js/app.js","src/services/mainService.js","src/coms/area/areaCtrl.js","src/coms/details/detailsCtrl.js","src/coms/details/singleCtrl.js","src/coms/home/homeCtrl.js","src/coms/rank/rankCtrl.js"], }, css: { src: ["src/css/bootstrap.min.css", "src/css/details.css", "src/css/font-awesome.min.css", "src/css/homepage.css", "src/css/ranking.css", "src/css/single.css", "src/css/tarea.css"], dest: "dist/css" }, assets: { src: ["src/assets/**/*.png", "src/assets/**/*.jpg"], dest: "dist/assets" } } } // 檢查腳本 gulp.task('jscheck', function() { gulp.src(config.paths.js.src) .pipe(g.jshint()) .pipe(g.jshint.reporter('default')); }); // 合併,壓縮js文件 gulp.task('minjs', function() { gulp.src(config.paths.js.src) .pipe(g.concat('app.js')) .pipe(gulp.dest('./dist')) .pipe(g.rename('app.min.js')) .pipe(g.uglify()) .pipe(gulp.dest('./dist')); }); // 合併,壓縮css文件 gulp.task('mincss', function() { gulp.src(config.paths.css.src) .pipe(g.concat('app.css')) .pipe(gulp.dest('./dist')) .pipe(g.rename('app.min.css')) .pipe(g.cssmin()) .pipe(gulp.dest('./dist')); }); // 轉移index.html到tmp目錄下 gulp.task('html', function() { gulp.src('./src/index.html') .pipe(g.rename('tmp.html')) .pipe(gulp.dest('./tmp')); }); // 打包 gulp.task('dist', function(){ gulp.run('jscheck', 'minjs', 'mincss'); }); // 默認任務 gulp.task('watch',['inject'], function () { browserSync({ notify: false, // Run as an https by uncommenting 'https: true' // Note: this uses an unsigned certificate which on first access // will present a certificate warning in the browser. // https: true, server: { baseDir:['src'], index: "index.html", middleware: [ historyApiFallback()] } }); // gulp.watch(config.paths.css.src, ['inject']); // gulp.watch(config.paths.js.src, ['inject']); gulp.watch([config.paths.html.src,config.paths.css.src,config.paths.js.src], ['inject']); gulp.watch([config.paths.html.src,'./src/index.html'], reload); }); // 測試環境運行 gulp.task('server', function(){ connect.server({ port: '3000', root: './src', middleware: function(connect, opt) { return [ historyApiFallback({}) ]; } }); }); // inject css js gulp.task('inject', function(){ return gulp.src('./src/index.html') .pipe(inject(gulp.src(config.paths.js.src, {read: false}), {ignorePath: 'src'})) .pipe(inject(gulp.src(config.paths.css.src, {read: false}), {ignorePath: 'src'})) .pipe(gulp.dest('./src')) }) gulp.task('default', ['inject', 'watch']);
發現其中有不少gulp.task,多是命中其中某個task,就拋出異常了,因而我嘗試gulp server,server是其中一個task的名字,沒想到竟然好了。jquery