首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Grunt返回无法获取/,ModRewrite不起作用

Grunt返回无法获取/,ModRewrite不起作用
EN

Stack Overflow用户
提问于 2018-01-29 17:03:25
回答 1查看 74关注 0票数 0

我是Grunt的新手(本周五开始)。当我运行Grunt Serve时,它会打开一个只有"cannot GET/“字样的页面。我找到了ModRewrite修复并实现了它。然而,当我尝试让我的grunt工作时,它仍然返回相同的错误。

任何帮助都将不胜感激

这是我的Gruntfile:

代码语言:javascript
复制
/* global module:true 
 * 
 * Gruntfile.js
 * npm install -g grunt-cli
 * npm install grunt-contrib-less grunt-contrib-watch grunt-contrib-connect --save-dev
 */
module.exports = function(grunt) {
    'use strict';

    var serveStatic = require('serve-static');

    var phpMiddleware = require('connect-php');

    var modRewrite = require('connect-modrewrite')

    grunt.initConfig({

      connect: {
        server: {
          options: {
            port: 8765,
            livereload: 35729,
            open: true,
            middleware: function(connect, options) {
              var middlewares;
              middlewares = [];

              middlewares.push( modRewrite( ['^[^\\.]*$ /index.html [L]'] ) );


              var directory = options.directory || options.base[options.base.length - 1];
              if (!Array.isArray(options.base)) {
                  options.base = [options.base];
              }

              // Magic happens here 
              middlewares.push(phpMiddleware(directory));

              options.base.forEach(function(base) {
                  // Serve static files. 
                  middlewares.push(serveStatic(base));
              });

              // Make directory browse-able. 
              //middlewares.push(connect.directory(directory));
              return middlewares;

            }
          }
        }
      }
      ,
      // Less files are in app/less, output is in app/css
      less: {
        development: {
          options: {
            paths: ["./less"],
            yuicompress: false
          },
          files: {
          "./css/style.css": "./less/style.less"
          }
        }
      },
      watch: {
        options: {
          livereload: 35729
        },
        files: "./less/*.less",
        tasks: ["less"]
      },

      uglify: {
        dist: {
            options: {
                sourceMap: 'js/map/source-map.js'
            },
            files: {
                'js/plugins.min.js': [
                    'js/source/plugins.js',
                    'js/vendor/**/*.js',
                    'js/vendor/modernizr*.js'
                ],
                'js/main.min.js': [
                    'js/source/main.js'
                ]
            }
          }
        }
      });

    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-uglify');

    // Run grunt server to get going
    grunt.registerTask('serve', [
      'connect',
      'watch'
    ]);

    grunt.registerTask('server', function () {
      grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
      grunt.task.run(['serve']);
    });

  };
EN

回答 1

Stack Overflow用户

发布于 2018-01-29 21:14:32

更改的middlewares.push( modRewrite( ['^[^\\.]*$ /index.html [L]'] ) );

转到middlewares.push( modRewrite( ['^[^\\.]*$ /index.php [L]'] ) );

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48497601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档