我不能再尝试了,很多小时,但什么也没有。问题来自 LiveReload,我没有将更改重新加载到浏览器。我可以说,如果它适用于编译的 js 和 css,但不适用于 livereload。
我把我的 gruntfile.js 放在这里,看看你能不能看到错误。
grunt test --verbose
我已经完成了许多测试,终端向我显示了以下内容,但实际上并没有在浏览器中重新加载。
Running "recess:dist" (recess) task
Verifying property recess.dist exists in config...OK
Files: ./css/landing.less -> ./css/landing.css
Options: banner="", compress, footer="", report=null, compile
Writing ./css/landing.css...OK
File "./css/landing.css" created.
Original: 4553 bytes.
Minified: 3687 bytes.
Done, without errors.
Live reloading css/landing.less...
Completed in 4.493s at Fri Jan 03 2014 15:51:37 GMT+0100 (CET) - Waiting...
php: estructura.php has changed
OK
>> File "template.php" changed.
Live reloading template.php...
Completed in 0.001s at Fri Jan 03 2014 15:51:54 GMT+0100 (CET) - Waiting...
grunfile.js
'use strict';
var path = require('path');
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
var gateway = require('gateway');
var phpGateway = function (dir){
return gateway(require('path').resolve(dir), {
'.php': 'php-cgi'
});
};
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
miapp: {
app: '.'
},
concat: {
all: {
src: "./js/*.js",
dest: "./js/todos.js"
},
},
uglify: {
options:{
banner: '/* <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
my_target: {
files: {
'js/landing.min.js': ['js/landing.js']
},
},
},
recess: {
dist: {
options: {
compile: true,
compress:true
},
files: {
'./css/landing.css': ['./css/landing.less']
},
},
},jshint:{
all:['./js/landing.js']
},jsonlint: {
sample: {
src: [ 'some/valid.json' ]
},
},imagemin: { // Task
static: { // Target
options: { // Target options
optimizationLevel: 3
}
},
dynamic: { // Another target
files: [{
expand: true, // Enable dynamic expansion
cwd: './', // Src matches are relative to this path
src: ['**/images/*.{png,jpg,gif}'], // Actual patterns to match
dest: 'test/' // Destination path prefix
}]
},
},watch: {
options: {
livereload: true
},
css:{
files: ['css/landing.less'],
tasks: ['recess'],
},
js:{
files: ['js/landing.js'],
tasks: ['build']
},
php:{
files: ['./**/*.php']
},
// images:{
// options: { livereload: true },
// files: [ 'images/**/*.{png,jpg,jpeg,gif,webp,svg}']
// }
},php: {
dev:{
options: {
port: 8000,
// keepalive: true,
open: true,
base: '<%= miapp.app %>',
hostname: 'localhost'
}
},
watch: {
options: {
livereload: 45678
},
}
},mocha: {
all: {
options: {
run: true,
urls: ['http://<%= php.dev.options.hostname %>:<%= php.dev.options.port %>/*.php']
}
}
},
bower: {
dev: {
dest: './components'
},
},
'bower-install': {
app: {
src: ['template.php']
},
},
});
grunt.event.on('watch', function(action, filepath, target) {
grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
});
// registramos las tareas (plugins) desde npm en Grunt
//grunt.loadTasks('tasks');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-recess');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-jsonlint');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-bower-task');
grunt.loadNpmTasks('grunt-bower-install');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-php');
grunt.loadNpmTasks('grunt-mocha');
//grunt.loadTasks('watch');
//grunt.registerTask('watch', ['watch']);
// registramos las tareas que se pueden ejecutar y el orden
grunt.registerTask("test", ["php","watch"]);
grunt.registerTask("default", ["uglify","connect","recess","watch" ]);
grunt.registerTask("build", ["concat", "uglify", "recess"]);
grunt.registerTask("load", ["connect"]);
grunt.registerTask("js", ["jshint"]);
grunt.registerTask("plantilla", ["bower-install"]);
grunt.registerTask("images", ["imagemin"]);
//grunt.registerTask('watch', ['watch']);
};
我希望你能帮助我。