运行'Grunt'时,HTML文件未添加到已编译的文件夹中 - Yeoman scaffold

时间:2013-11-11 17:28:45

标签: node.js gruntjs yeoman

我用Yeoman来支撑我的网站。我想使用jade模板到目前为止工作一半,我的jade文件转到tmp作为html文件夹,livereload显示这很好,但当我运行grunt来构建我的网站时,文件夹.tmp中的html文件不会得到放入我的public_html文件夹。所有其他文件夹/资产都按预期进入public_html。

这是我的文件夹结构为坏插图道歉:

  • 网站名称
    ---- .sass缓存
    ---- .tmp

  • 应用
    ---- bower_components
    ----图像
    ----玉 ----脚本
    ----样式

  • 的public_html
    ---- bower_components
    ----脚本
    ----样式

    // Generated on 2013-11-11 using generator-webapp 0.4.3
    'use strict';
    
    // # Globbing
    // for performance reasons we're only matching one level down:
    // 'test/spec/{,*/}*.js'
    // use this if you want to recursively match all subfolders:
    // 'test/spec/**/*.js'
    
    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({
        // configurable paths
        site_name: {
            app: 'app',
            public_html: 'public_html'
        },
        watch: {
            compass: {
                files: ['<%= site_name.app %>/styles/{,*/}*.{scss,sass}'],
                tasks: ['compass:server', 'autoprefixer']
            },
            styles: {
                files: ['<%= site_name.app %>/styles/{,*/}*.css'],
                tasks: ['copy:styles', 'autoprefixer']
            },
            jade: {
                files: ['<%= site_name.app %>/jade/{,*/}*.jade'],
                tasks: ['jade']
            },
            livereload: {
                options: {
                    livereload: '<%= connect.options.livereload %>'
                },
                files: [
                    '.tmp/{,*/}*.html',
                    '.tmp/styles/{,*/}*.css',
                    '{.tmp,<%= site_name.app %>}/scripts/{,*/}*.js',
                    '<%= site_name.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
                ]
            }
        },
        connect: {
            options: {
                port: 9000,
                livereload: 35729,
                // change this to '0.0.0.0' to access the server from outside
                hostname: 'localhost'
            },
            livereload: {
                options: {
                    open: true,
                    base: [
                        '.tmp',
                        '<%= site_name.app %>'
                    ]
                }
            },
            test: {
                options: {
                    base: [
                        '.tmp',
                        'test',
                        '<%= site_name.app %>'
                    ]
                }
            },
            public_html: {
                options: {
                    open: true,
                    base: '<%= site_name.public_html %>'
                }
            }
        },
        clean: {
            public_html: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        '<%= site_name.public_html %>/*',
                        '!<%= site_name.public_html %>/.git*'
                    ]
                }]
            },
            server: '.tmp'
        },
        jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            all: [
                'Gruntfile.js',
                '<%= site_name.app %>/scripts/{,*/}*.js',
                '!<%= site_name.app %>/scripts/vendor/*',
                'test/spec/{,*/}*.js'
            ]
        },
        mocha: {
            all: {
                options: {
                    run: true,
                    urls: ['http://<%= connect.test.options.hostname %>:<%= connect.test.options.port %>/index.html']
                }
            }
        },
        compass: {
            options: {
                sassDir: '<%= site_name.app %>/styles',
                cssDir: '.tmp/styles',
                generatedImagesDir: '.tmp/images/generated',
                imagesDir: '<%= site_name.app %>/images',
                javascriptsDir: '<%= site_name.app %>/scripts',
                fontsDir: '<%= site_name.app %>/styles/fonts',
                importPath: '<%= site_name.app %>/bower_components',
                httpImagesPath: '/images',
                httpGeneratedImagesPath: '/images/generated',
                httpFontsPath: '/styles/fonts',
                relativeAssets: false,
                assetCacheBuster: false
            },
            public_html: {
                options: {
                    generatedImagesDir: '<%= site_name.public_html %>/images/generated'
                }
            },
            server: {
                options: {
                    debugInfo: true
                }
            }
        },
        autoprefixer: {
            options: {
                browsers: ['last 1 version']
            },
            public_html: {
                files: [{
                    expand: true,
                    cwd: '.tmp/styles/',
                    src: '{,*/}*.css',
                    dest: '.tmp/styles/'
                }]
            }
        },
        // not used since Uglify task does concat,
        // but still available if needed
        /*concat: {
            public_html: {}
        },*/
        'bower-install': {
            app: {
                html: '<%= site_name.app %>/index.html',
                ignorePath: '<%= site_name.app %>/'
            }
        },
        // not enabled since usemin task does concat and uglify
        // check index.html to edit your build targets
        // enable this task if you prefer defining your build targets here
        /*uglify: {
            public_html: {}
        },*/
        rev: {
            public_html: {
                files: {
                    src: [
                        '<%= site_name.public_html %>/scripts/{,*/}*.js',
                        '<%= site_name.public_html %>/styles/{,*/}*.css',
                        '<%= site_name.public_html %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}',
                        '<%= site_name.public_html %>/styles/fonts/{,*/}*.*'
                    ]
                }
            }
        },
        jade: {
            public_html: {
                options: {
                    pretty: true
                },
                files: [{
                    expand: true,
                    cwd: '<%= site_name.app %>/jade',
                    dest: '.tmp',
                    src: '{,*/}*.jade',
                    ext: '.html'
                }]
            }
        },
        useminPrepare: {
            options: {
                dest: '<%= site_name.public_html %>'
            },
            html: '<%= site_name.app %>/index.html'
        },
        usemin: {
            options: {
                dirs: ['<%= site_name.public_html %>']
            },
            html: ['<%= site_name.public_html %>/{,*/}*.html'],
            css: ['<%= site_name.public_html %>/styles/{,*/}*.css']
        },
        imagemin: {
            public_html: {
                files: [{
                    expand: true,
                    cwd: '<%= site_name.app %>/images',
                    src: '{,*/}*.{png,jpg,jpeg}',
                    dest: '<%= site_name.public_html %>/images'
                }]
            }
        },
        svgmin: {
            public_html: {
                files: [{
                    expand: true,
                    cwd: '<%= site_name.app %>/images',
                    src: '{,*/}*.svg',
                    dest: '<%= site_name.public_html %>/images'
                }]
            }
        },
        cssmin: {
            // This task is pre-configured if you do not wish to use Usemin
            // blocks for your CSS. By default, the Usemin block from your
            // `index.html` will take care of minification, e.g.
            //
            //     <!-- build:css({.tmp,app}) styles/main.css -->
            //
            // public_html: {
            //     files: {
            //         '<%= site_name.public_html %>/styles/main.css': [
            //             '.tmp/styles/{,*/}*.css',
            //             '<%= site_name.app %>/styles/{,*/}*.css'
            //         ]
            //     }
            // }
        },
        htmlmin: {
            public_html: {
                options: {
                    /*removeCommentsFromCDATA: true,
                    // https://github.com/murata/grunt-usemin/issues/44
                    //collapseWhitespace: true,
                    collapseBooleanAttributes: true,
                    removeAttributeQuotes: true,
                    removeRedundantAttributes: true,
                    useShortDoctype: true,
                    removeEmptyAttributes: true,
                    removeOptionalTags: true*/
                },
                files: [{
                    expand: true,
                    cwd: '.tmp',
                    src: '*.html',
                    dest: '<%= site_name.public_html %>'
                }]
            }
        },
        // Put files not handled in other tasks here
        copy: {
            public_html: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: '<%= site_name.app %>',
                    dest: '<%= site_name.public_html %>',
                    src: [
                        '*.{ico,png,txt}',
                        '.htaccess',
                        'images/{,*/}*.{webp,gif}',
                        'styles/fonts/{,*/}*.*',
                        'bower_components/sass-bootstrap/fonts/*.*'
                    ]
                }]
            },
            styles: {
                expand: true,
                dot: true,
                cwd: '<%= site_name.app %>/styles',
                dest: '.tmp/styles/',
                src: '{,*/}*.css'
            }
        },
        modernizr: {
            devFile: '<%= site_name.app %>/bower_components/modernizr/modernizr.js',
            outputFile: '<%= site_name.public_html %>/bower_components/modernizr/modernizr.js',
            files: [
                '<%= site_name.public_html %>/scripts/{,*/}*.js',
                '<%= site_name.public_html %>/styles/{,*/}*.css',
                '!<%= site_name.public_html %>/scripts/vendor/*'
            ],
            uglify: true
        },
        concurrent: {
            server: [
                'compass',
                'copy:styles'
            ],
            test: [
                'copy:styles'
            ],
            public_html: [
                'compass',
                'copy:styles',
                'imagemin',
                'svgmin',
                'htmlmin'
            ]
        }
    });
    
    grunt.registerTask('server', function (target) {
        if (target === 'public_html') {
            return grunt.task.run(['build', 'connect:public_html:keepalive']);
        }
    
        grunt.task.run([
            'clean:server',
            'jade',
            'concurrent:server',
            'autoprefixer',
            'connect:livereload',
            'watch'
        ]);
    });
    
    grunt.registerTask('test', [
        'clean:server',
        'concurrent:test',
        'autoprefixer',
        'connect:test',
        'mocha'
    ]);
    
    grunt.registerTask('build', [
        'clean:public_html',
        'useminPrepare',
        'concurrent:public_html',
        'jade',
        'autoprefixer',
        'concat',
        'cssmin',
        'uglify',
        'modernizr',
        'copy:public_html',
        'rev',
        'usemin'
    ]);
    
    grunt.registerTask('default', [
        /*'jshint',*/
        'test',
        'build'
    ]);
    

    };

2 个答案:

答案 0 :(得分:0)

运行grunt htmlmin时会发生什么?

由于某种原因,我认为htmlmin任务没有运行。也许它没有因为concurrent任务而运行,就像在另一个SO答案中一样:

请注意,在您的gruntfile中,htmlmin声明会将.tmp中的html文件复制到<%= site_name.public_html %>

您也可以尝试grunt build --force让grunt继续执行可能阻止grunt最终运行htmlmin的任何错误。

答案 1 :(得分:0)

认为您的问题出在您的htmlmin任务中

htmlmin: {
    public_html: {
        options: {
            /*removeCommentsFromCDATA: true,
            // https://github.com/murata/grunt-usemin/issues/44
            //collapseWhitespace: true,
            collapseBooleanAttributes: true,
            removeAttributeQuotes: true,
            removeRedundantAttributes: true,
            useShortDoctype: true,
            removeEmptyAttributes: true,
            removeOptionalTags: true*/
        },
        files: [{
            expand: true,
            cwd: '.tmp',
            src: '*.html',
            dest: '<%= site_name.public_html %>'
        }]
    }
},

需要/在'&lt;%= site_name.public_html%&gt;'结尾处例如

dest: '<%= site_name.public_html %>/'

也许?