【问题标题】:I'm using Grunt for my angular 1 app and grunt-connect to run the website, but on refresh it doesnt have a fallback so I get a 404 and white screen我将 Grunt 用于我的 angular 1 应用程序并使用 grunt-connect 来运行网站,但在刷新时它没有后备,所以我得到一个 404 和白屏
【发布时间】:2016-03-17 20:55:43
【问题描述】:

我在我的 angular 1 应用程序中使用 Grunt,并使用 grunt-connect 来运行网站,但在刷新时它没有回退,所以我得到 404 和白屏。

我以前用过 gulp,它的连接插件有一个后备。

我要解决的问题是,当我刷新浏览器时,我失去了网站并出现 404 和白屏。

我对咕噜很陌生。

这是我当前的 grunt 代码:

module.exports = function(grunt) {

        //Configures each plugin:   
        grunt.initConfig({

        //This is the connect bit:
         connect: {
            website: {
                port: 8000,
                base: 'app'
            }
         },

          sass: {                              // Task 
            dist: {                            // Target 
              options: {                       // Target options 
                style: 'expanded'
              },
              files: {                         // Dictionary of files 
                'app/styles/styles.css': 'app/styles/base.scss'   // 'destination': 'source'
              }
            }
          },
          cssmin: {
              target: {
                files: [{
                  expand: true,
                  cwd: 'app/styles',
                  src: ['*.css', '!*.min.css'],
                  dest: 'app/styles',
                  ext: '.min.css'
                }]
              }
           },   
           watch: {

                    css: {
                        files: 'app/styles/base.scss',
                        tasks: ['sass'],
                        options: {
                          livereload: {
                            host: 'localhost',
                            port: 8000
                          },
                          spawn: true,
                          interrupt: true,
                          debounceDelay: 250,
                          reload: true
                        },
                    }    
            } 
        });      

        //Loads libruaries:
        grunt.loadNpmTasks('grunt-contrib-sass');
        grunt.loadNpmTasks('grunt-contrib-cssmin');
        grunt.loadNpmTasks('grunt-contrib-watch');
        grunt.loadNpmTasks('grunt-contrib-jshint');
        grunt.loadNpmTasks('grunt-connect');

        //grunt.registerTask('default', ['sass', 'cssmin', 'jshint', 'connect', 'watch']);

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

错误截图:

【问题讨论】:

    标签: javascript angularjs gruntjs grunt-connect


    【解决方案1】:

    您的connect 缺少选项..

     connect: {
                website: {
                    port: 8000,
                    base: 'app',
                    keepalive: true,
                    livereload: true
                }
             },
    

    【讨论】:

    • 我添加了上面发生的屏幕截图
    猜你喜欢
    • 2016-03-28
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    • 2014-09-25
    相关资源
    最近更新 更多