咕噜咕噜这个网站无法联系到

时间:2016-05-22 16:50:23

标签: gruntjs

由于某些原因,从终端运行grunt不起作用。当我运行grunt dev并打开http://localhost:8000/时,它可以正常运行,但当我使用grunt时,它会显示This site can’t be reached. localhost refused to connect.

我缺少什么想法?

'use strict';
var path = require('path');
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;

var folderMount = function folderMount(connect, point) {
  return connect.static(path.resolve(point));
};

module.exports = function (grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    clean: {
      build: {
        src: [".sass-cache"]
      }
    }, // end clean

    sass: {
      dist: {
        options: {
          style: 'expanded',
          noCache: true
        },
        files: {
          'app/production/css/style.css': 'app/scss/style.scss'
        }
      }
    }, // end sass

    cssmin: {
      target: {
        files: [{
          expand: true,
          cwd: 'app/production/css',
          src: ['*.css', '!*.min.css'],
          dest: 'app/production/css',
          ext: '.min.css'
        }]
      }
    }, //end cssmin

    connect: {
      server: {
        options: {
          port: 8000
        }
      }
    }, // end connect

    uglify: {
      options: {
        mangle: false
      },
      my_target: {
        files: {
          'app/production/js/app.min.js': ['app/js/module.js', 'app/js/config.js', 'app/js/factory.js', 'app/js/filter.js', 'app/js/PotatoAppController.js']
        }
      }
    }, // end js minify

    watch: { // this is a watcher, to run this in terminal write: grunt watch
      options: {
        dateFormat: function(time) {
          grunt.log.writeln('The watch finished in ' + time + 'ms at' + (new Date()).toString());
          grunt.log.writeln('Waiting for new changes ...');
        },
        livereload: true
      },

      css: {
        files: 'app/scss/style.scss',
        tasks: ['sass', 'cssmin']
      },

      jsmin: {
        files: 'app/js/*.js',
        tasks: ['uglify']
      },

      html: {
            files: ['app/views/**/*.html'],
            options: {
                livereload: true
            }
        }
    } // end watch
  });

  grunt.loadNpmTasks('grunt-contrib-watch');    // Load the plugin that provides the "watch" task.
  grunt.loadNpmTasks('grunt-contrib-cssmin');   // Load the plugin that provides the "cssmin" task.
  grunt.loadNpmTasks('grunt-contrib-sass');   // Load the plugin that provides the "sass" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');   // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-livereload'); // Load the plugin that provides the "livereload" task.
  grunt.loadNpmTasks('grunt-contrib-connect');  // Load the plugin that provides the "connect" task.
  grunt.loadNpmTasks('grunt-contrib-clean');    // Load the plugin that provides the "clean" task.

  grunt.registerTask('default', ['watch']);   // this is the default command, use in terminal 'grunt'
  grunt.registerTask('dev', ['connect', 'sass', 'cssmin', 'uglify', 'clean', 'watch']);  // use 'grunt dev' for development
};

1 个答案:

答案 0 :(得分:0)

执行' grunt','默认'命令将被执行。

在您的情况下,只有'观看'任务已执行。

grunt.registerTask('default', ['watch']);

如果您想要访问“localhost'”,则需要运行“连接”#39;模块。 '看'任务只是观察文件的变化。不要启动网络服务器。

'连接'用于启动Web服务器。

感谢。

相关问题