GULP - ReferenceError:未定义窗口

时间:2016-07-12 14:45:33

标签: angularjs gulp minify

我在gulp watch中遇到了问题。

我压缩通过Bower安装的角度文件。

使用:gulp-ngmin,gulp-concat。

我的gulp文件是:



var gulp      = require('gulp'),
	sass        = require('gulp-ruby-sass'),
	imagemin    = require('gulp-imagemin'),
	changed     = require('gulp-changed'),
	browserSync = require('browser-sync'),
    livereload = require('gulp-livereload'),    
    gp_concat = require('gulp-concat'),
    gp_rename = require('gulp-rename'),
    watch = require('gulp-watch'),
    ngmin = require('gulp-ngmin');
    

gulp.task('sass', function () {
 return sass('./app/template/css/style_v1.scss')
    .on('error', function (err) { console.log(err.message); })
    .pipe(gulp.dest('./dist/css'))
    .pipe(livereload());
});

gulp.task('compress', function() {
  gulp.src([
            'bower_components/angular/angular.min.js',
            'bower_components/angular-animate/angular-animate.min.js',
            'bower_components/angular-aria/angular-aria.min.js',
            'bower_components/angular-material/angular-material.min.js',
            'bower_components/angular-messages/angular-messages.min.js',
            'bower_components/jquery/dist/jquery.min.js',
            'bower_components/bootstrap/dist/js/bootstrap.min.js',
            'bower_components/angular-ui-router/release/angular-ui-router.min.js',
            './app/*.js'
            ])
        .pipe(gp_concat('concat.js'))        
        .pipe(gp_rename('script.min.js'))
        .pipe(ngmin({dynamic: true}).on('error', function(e){
            console.log(e);
         }))
        .pipe(gulp.dest('./dist/js'));
});

gulp.task('jpg', function() {
	gulp.src('./template/img/**/*.*')
		.pipe(changed('./dist/img/'))
		.pipe(imagemin({
			progressive: true
		}))
		.pipe(gulp.dest('./dist/img/'));
});

gulp.task('browser-sync', function() {
    browserSync.init(['./dist/css/**', 'index.html'], {
        server: {
            baseDir: './',
            index: 'index.html'
        }
    });
});

gulp.task('watch', ['sass', 'browser-sync','compress'], function () { 
    return watch('./app/template/css/style_v1.scss', function () {
        gulp.src('./app/template/css/style_v1.scss')
            .pipe(gulp.dest('build'));
    });
});




当我运行gulp watch时,它会返回此错误:



[11:21:13] Starting 'watch'...
{ ReferenceError: window is not defined
    at eval (eval at run (/var/www/html/evandro/sistema_metas/node_modules/ngmin-dynamic/dynamic.js:208:14), <anonymous>:315:158)
    at run (/var/www/html/evandro/sistema_metas/node_modules/ngmin-dynamic/dynamic.js:208:3)
    at Object.exports.annotate (/var/www/html/evandro/sistema_metas/node_modules/ngmin/main.js:13:12)
    at Transform._transform (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/index.js:19:37)
    at Transform._read (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at Transform._write (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_writable.js:237:10)
    at writeOrBuffer (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_writable.js:227:5)
    at Transform.Writable.write (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_writable.js:194:11)
    at Transform.ondata (_stream_readable.js:561:20)
  plugin: 'gulp-ngmin',
  showStack: false,
  name: 'ReferenceError',
  message: 'window is not defined',
  stack: 'ReferenceError: window is not defined\n    at eval (eval at run (/var/www/html/evandro/sistema_metas/node_modules/ngmin-dynamic/dynamic.js:208:14), <anonymous>:315:158)\n    at run (/var/www/html/evandro/sistema_metas/node_modules/ngmin-dynamic/dynamic.js:208:3)\n    at Object.exports.annotate (/var/www/html/evandro/sistema_metas/node_modules/ngmin/main.js:13:12)\n    at Transform._transform (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/index.js:19:37)\n    at Transform._read (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_transform.js:184:10)\n    at Transform._write (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_transform.js:172:12)\n    at doWrite (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_writable.js:237:10)\n    at writeOrBuffer (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_writable.js:227:5)\n    at Transform.Writable.write (/var/www/html/evandro/sistema_metas/node_modules/gulp-ngmin/node_modules/readable-stream/lib/_stream_writable.js:194:11)\n    at Transform.ondata (_stream_readable.js:561:20)' }
&#13;
&#13;
&#13;

什么是window is not defined

Ps:可能是某些错误脚本不兼容,我在其他问题中发现了这一点。

0 个答案:

没有答案