5
votes

I used Yeoman to scaffold my site. I want to use jade templates which so far is half working, my jade files go to the tmp as html files folder and livereload is displaying this fine, but when I run grunt to build my site the html files from folder .tmp do not get placed into my public_html folder. All other folders/assets as expected are going to public_html.

Here is my folder structure apologies for the bad illustration:

  • site name
    ---- .sass cache
    ---- .tmp

  • app
    ---- bower_components
    ---- images
    ---- jade
    ---- scripts
    ---- styles

  • public_html
    ---- bower_components
    ---- scripts
    ---- styles

    // 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

2 Answers

0
votes

What happens when you run grunt htmlmin?

I'm thinking that the htmlmin task isn't running, for some reason. Perhaps it's not running because of the concurrent task, as in this other SO answer:

Notice that in your gruntfile, the htmlmin declaration copies html files from .tmp into <%= site_name.public_html %>.

You might also try grunt build --force to make grunt continue through any errors that may be preventing grunt from eventually running htmlmin.

0
votes

Think your issue is in your htmlmin task

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 %>'
        }]
    }
},

needs / at end of '<%= site_name.public_html %>' eg

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

maybe ?