【问题标题】:Grunt apply changes after edit js files编辑 js 文件后 Grunt 应用更改
【发布时间】:2016-04-19 08:41:34
【问题描述】:

我使用 Grunt 创建了第一个项目。我有一个问题,因为在编辑 js 文件后我需要重新启动服务器以应用更改。当我编辑 JADE 文件时,我不需要重新启动服务器。还有一个问题:如何在文件更改后添加自动刷新浏览器?

我的 gruntfile:

'use strict';

module.exports = function (grunt) {
    // show elapsed time at the end
    require('time-grunt')(grunt);
    // load all grunt tasks
    require('load-grunt-tasks')(grunt);

    grunt.initConfig({
        reload: {
            port: 9000,
            proxy: {
                host: 'localhost'
            }
        },
        // Watch Config
        watch: {
            files: ['views/**/*','routes/*'],
            taksks: 'workon reload',
            options: {
                nospawn: true // Without this option specified express won't be reloaded
            },
            express: {
                files:  [ 'app.js', '!**/node_modules/**', '!Gruntfile.js' ],
                tasks:  [ 'express:dev' ],
                options: {
                    nospawn: true // Without this option specified express won't be reloaded
                }
            }
        },


        // Clean Config
        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        'dist/*',
                        '!dist/.git*'
                    ]
                }]
            },
            server: ['.tmp']
        },
        // Express Config
        express: {
            options: {
              // Override defaults here
            },
            dev: {
                options: {
                    script: './bin/www'
                }
            }
        },
        // Open Config
        open: {
            site: {
                path: 'http://localhost:9000',
                app: 'chrome'
            }
        }

    });

    // Register Tasks
    // Workon
    grunt.registerTask('workon', 'Start working on this project.', [
        'express:dev',
        'open:site',
        'watch'
    ]);


    // Restart
    grunt.registerTask('restart', 'Restart the server.', [
        'express:dev',
        'open:site',
        'reload',
        'watch'

    ]);


    // Build
    grunt.registerTask('build', 'Build production ready assets and views.', [
        'clean:dist',
        'concurrent:dist',
        'useminPrepare',
        'imagemin',
        'concat',
        'cssmin',
        'uglify',
        'copy:dist',
        'rev',
        'usemin',
    ]);

    grunt.loadNpmTasks('grunt-express-server');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-open');
    grunt.loadNpmTasks('grunt-reload');


};

编辑:重新加载服务器页面后加载非常慢:

为什么?

【问题讨论】:

    标签: javascript node.js


    【解决方案1】:
      livereload: {
            options: {
              livereload: '<%= connect.options.livereload %>'
            },
            files: [
    
            ]
          }
    

    我觉得这部分的手表可以帮到你

    【讨论】:

    • 好的,谢谢。但是重新加载服务器网站后加载缓慢。为什么?
    • 你是否使用了一些浏览器的 livereload 插件?我读到它们可能与连接插件冲突。您也可以尝试指定文件(也许没有它连接照顾所有)
    • 我的浏览器中没有 livereload 插件。哪些文件?
    • '/{,/}.html' - 文件模式。如果来自此来源的具有此扩展名的文件将添加它重新加载页面。将其添加到实时重新加载部分的文件数组中。
    • 好的,我没有。我通过 express generator 生成了文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多