Grunt - 启动并运行livereload的服务器

时间:2014-07-21 16:20:53

标签: javascript gruntjs grunt-contrib-connect

我现在一直盯着我的咕噜声配置几个小时,但似乎无法正常运行。

我的文件正在构建我期待它们的地方(基本上就在它们所在的地方,除了把手)但我真的很难让自动清新服务器启动并运行。无法完全启动并运行。

如果有人能指出我正确的方向,这将是一个巨大的帮助!

module.exports = function(grunt) {

    grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        sass: {
            files: {
                'assets/css/style.css' : 'assets/css/*.scss'
            }       
        },
        assemble: {
            options: {
                flatten: true,
                assets: 'assets',
                layout: 'templates/layouts/main.hbs'
            },
            pages: {
                src: ['templates/*.hbs'],
                dest: '.'
            }
        },
        watch: {
            all: {
                files: '**/*.hbs',
                tasks: ['assemble'],
                options: {
                    livereload: true,
                }
            },
            css: {
                files: 'assets/css/*.scss',
                tasks: ['sass']
            },
            scripts: {
                files: 'assets/js/*.js',
            },
            livereload: {
                options : { livereload: true },
                files: ['/']
            }
        },
        connect: {
            options: {
                port: 9001,
                livereload: 35729,
                hostname: '0.0.0.0',
                keepalive: true,
                open: true
            }
        }
    });

    grunt.loadNpmTasks('assemble');
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-open');

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

1 个答案:

答案 0 :(得分:0)

这是我设法在朋友的帮助下工作 - 使用了一些过时的模块。希望它对某人有用!

  

module.exports = function(grunt){

grunt.initConfig({
    sass: {
        all: {
            files: {
                'assets/css/style.css' : 'assets/css/main.scss'
            }   
        }
    },
    assemble: {
        options: {
            flatten: true,
            assets: 'assets',
            layout: 'templates/layouts/main.hbs'
        },
        pages: {
            src: ['templates/*.hbs'],
            dest: '.'
        }
    },
    watch: {
        assemble: {
            files: 'templates/**/*.hbs',
            tasks: ['assemble']
        },
        sass: {
            files: 'assets/css/*.scss',
            tasks: ['sass']
        },
        css: {
            files:['assets/css/*.css']
        },
        scripts: {
            files: 'assets/js/*.js',
        },
        livereload: {
            options : { livereload: true },
            files: ['*.html','assets/css/*.css','assets/js/*.js']
        }
    },
    connect: {
        options: {
            port: 9001,
            livereload: true,
            hostname: '0.0.0.0'
        },
        livereload: {
            options: {
                open: true,
                base: ['.']
            }
        }
    }
});

grunt.loadNpmTasks('assemble');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');

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

}