我对Grunt非常陌生(本周五开始)。 当我运行Grunt Serve时,它打开一个只有单词&#34的页面;不能GET /"在上面。我找到了ModRewrite修复并实现了它。 然而,当我试图让我的咕噜声工作时,它仍然会返回相同的错误。
非常感谢任何帮助
这是我的Gruntfile:
/* 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']);
});
};
答案 0 :(得分:0)
更改了middlewares.push( modRewrite( ['^[^\\.]*$ /index.html [L]'] ) );
到middlewares.push( modRewrite( ['^[^\\.]*$ /index.php [L]'] ) );