grunt-includes插件不适用于livereload

时间:2013-12-04 11:34:25

标签: javascript gruntjs yeoman livereload

我有问题。 我在我的项目中使用https://github.com/vanetix/grunt-includes,安装后我的livereload插件停止工作,当我编辑html文件时,我没有看到更改。 Coud你帮帮我吗?

我的咕噜文件:

'use strict';
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
var mountFolder = function(connect, dir) {
    return connect.static(require('path').resolve(dir));
};

module.exports = function(grunt) {
    // load all grunt tasks
    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

    // configurable paths
    var yeomanConfig = {
        app: 'app',
        dist: 'dist'
    };

    grunt.initConfig({
        yeoman: yeomanConfig,
        watch: {
            coffee: {
                files: ['app/js/*.coffee'],
                tasks: ['coffee:dist']
            },
            coffeeTest: {
                files: ['test/spec/*.coffee'],
                tasks: ['coffee:test']
            },
            less: {
                files: ['app/less/**/*.less'],
                tasks: ['less']
            },
            includes: {
                files: ['app/*.html', '.tmp/*.html'],
                tasks: ['includes:server']
            },
            livereload: {
                files: [
                    'app/*.html',
                    '{.tmp,app}/css/*.css',
                    '{.tmp,app}/js/*.js',
                    '{.tmp,app}/widgets/**/*.js',
                    'app/img/*.{png,jpg,jpeg}'
                ],
                tasks: ['livereload']
            }
        },
        connect: {
            options: {
                port: 9000
            },
            livereload: {
                options: {
                    middleware: function(connect) {
                        return [
                            lrSnippet,
                            mountFolder(connect, '.tmp'),
                            mountFolder(connect, 'app')
                        ];
                    }
                }
            },
            test: {
                options: {
                    middleware: function(connect) {
                        return [
                            mountFolder(connect, '.tmp'),
                            mountFolder(connect, 'test')
                        ];
                    }
                }
            },
            dist: {
                options: {
                    middleware: function(connect) {
                        return [
                            mountFolder(connect, 'dist')
                        ];
                    }
                }
            }
        },
        open: {
            server: {
                url: 'http://localhost:<%= connect.options.port %>'
            }
        },
        clean: {
            dist: ['.tmp', 'dist/*'],
            server: '.tmp'
        },
        // jshint: {
        //     options: {
        //         jshintrc: '.jshintrc'
        //     },
        //     all: [
        //         'Gruntfile.js',
        //         'app/js/*.js',
        //         'test/spec/*.js'
        //     ]
        // },
        mocha: {
            all: ['http://localhost:3501/index.html']
        },
        coffee: {
            dist: {
                files: {
                    '.tmp/js/coffee.js': 'app/js/*.coffee'
                }
            },
            test: {
                files: [{
                    expand: true,
                    cwd: '.tmp/spec',
                    src: '*.coffee',
                    dest: 'test/spec'
                }]
            }
        },
        includes: {
            build: {
                cwd: 'app',
                src: ['*.html', 'pages/*.html'],
                dest: 'dist',
                options: {
                    flatten: true,
                    banner: ''
                }
            },
            server: {
                cwd: 'app',
                src: ['*.html', 'pages/*.html'],
                dest: '.tmp/',
                options: {
                    flatten: true,
                    banner: ''
                }
            }
        },
        less: {
            options: {
                paths: ['app/less'],
                //dumpLineNumbers: true
            },
            dist: {
                files: [{
                    expand: true, // Enable dynamic expansion.
                    cwd: 'app/css/', // Src matches are relative to this path.
                    src: ['**/*.less'], // Actual pattern(s) to match.
                    dest: '.tmp/css/', // Destination path prefix.
                    ext: '.css', // Dest filepaths will have this extension.
                }],
            },
            server: {
                files: [{
                    expand: true, // Enable dynamic expansion.
                    cwd: 'app/less/', // Src matches are relative to this path.
                    src: ['**/*.less'], // Actual pattern(s) to match.
                    dest: '.tmp/css/', // Destination path prefix.
                    ext: '.css', // Dest filepaths will have this extension.
                }],
            }
        },
        // not used since Uglify task does concat,
        // but still available if needed
        /*concat: {
            dist: {}
        },*/
        // requirejs: {
        //     dist: {
        //         // Options: https://github.com/jrburke/r.js/blob/master/build/example.build.js
        //         options: {
        //             // `name` and `out` is set by grunt-usemin
        //             baseUrl: 'app/js',
        //             optimize: 'none',
        //             // TODO: Figure out how to make sourcemaps work with grunt-usemin
        //             // https://github.com/yeoman/grunt-usemin/issues/30
        //             //generateSourceMaps: true,
        //             // required to support SourceMaps
        //             // http://requirejs.org/docs/errors.html#sourcemapcomments
        //             preserveLicenseComments: false,
        //             useStrict: true,
        //             wrap: true,
        //             //uglify2: {} // https://github.com/mishoo/UglifyJS2
        //             mainConfigFile: 'app/js/main.js'
        //         }
        //     }
        // },
        useminPrepare: {
            html: 'app/*.html',
            options: {
                dest: 'dist'
            }
        },
        usemin: {
            html: ['dist/*.html'],
            css: ['dist/css/*.css'],
            options: {
                dirs: ['dist']
            }
        },
        imagemin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: 'app/img',
                    src: '**/*.{png,jpg,jpeg}',
                    dest: 'dist/img'
                }]
            }
        },
        cssmin: {
            dist: {
                files: {
                    'dist/css/main.css': [
                        '.tmp/css/*.css',
                        'app/css/*.css'
                    ]
                }
            }
        },
        htmlmin: {
            dist: {
                options: {
                    removeCommentsFromCDATA: true,
                    // https://github.com/yeoman/grunt-usemin/issues/44
                    //collapseWhitespace: true,
                    collapseBooleanAttributes: true,
                    removeAttributeQuotes: true,
                    removeRedundantAttributes: true,
                    useShortDoctype: true,
                    removeEmptyAttributes: true,
                    removeOptionalTags: true
                },
                files: [{
                    expand: true,
                    cwd: 'app',
                    src: '**/*.html',
                    dest: 'dist'
                }]
            }
        },
        copy: {
            dist: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: 'app',
                    dest: 'dist',
                    src: [
                        '*.{ico,txt}',
                        //'*.html',
                        'fonts/*.*',
                        '.htaccess'
                    ]
                }]
            }
        },
        bower: {
            rjsConfig: 'app/js/main.js',
            indent: '    '
        }
    });

    grunt.renameTask('regarde', 'watch');
    // remove when mincss task is renamed
    grunt.renameTask('mincss', 'cssmin');
    grunt.loadNpmTasks('grunt-includes');
    grunt.registerTask('server', function(target) {
        if (target === 'dist') {
            return grunt.task.run(['open', 'connect:dist:keepalive']);
        }

        grunt.task.run([
            'clean:server',
            'coffee:dist',
            'less:server',
            'includes:server',
            'livereload-start',
            'connect:livereload',
            'open',
            'watch'
        ]);
    });

    grunt.registerTask('test', [
        'clean:server',
        'coffee',
        'less',
        'connect:test',
        'mocha'
    ]);

    grunt.registerTask('build', [
        'clean:dist',
        'test',
        'coffee',
        'less:dist',
        'useminPrepare',
        'includes:build',
        'imagemin',
        'cssmin',
        'htmlmin',
        'concat',
        'uglify',
        'copy',
        'usemin'
    ]);

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

编辑:

我只是移动包括:服务器到liverelad功能,它的工作。

livereload: {
                files: [
                    'app/*.html',
                    '{.tmp,app}/css/*.css',
                    '{.tmp,app}/js/*.js',
                    '{.tmp,app}/widgets/**/*.js',
                    'app/img/*.{png,jpg,jpeg}'
                ],
                tasks: ['livereload', 'includes:server']
            }

0 个答案:

没有答案