运行'Grunt'时,HTML文件不会添加到编译的文件夹 – Yeoman脚手架

我用Yeoman脚手架我的网站。 我想使用到目前为止是一半的玉模板,我的玉文件作为html文件文件夹去tmp,livereload显示这个罚款,但是当我运行grunt来build立我的网站从文件夹.tmp的HTML文件不会得到放入我的public_html文件夹。 所有其他文件夹/资产按预期将public_html。

这是我的文件夹结构道歉的坏例证:

  • 网站名称
    —- .sasscaching
    —- .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, eg // // <!-- 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' ]); 

    };

       

网上收集的解决方案 "运行'Grunt'时,HTML文件不会添加到编译的文件夹 – Yeoman脚手架"

当你运行grunt htmlmin会发生什么?

我在想,由于某种原因, htmlmin任务没有运行。 也许它没有运行,因为concurrent任务,如在这个其他答案:

  • Grunt构build – 运行“concurrent:dist”(并发)任务被终止

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

你也可以试试grunt build --force ,通过任何可能阻止最终运行htmlmin咕噜声的错误继续。

认为你的问题是在你的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 %>' }] } }, 

需要/在“<%= site_name.public_html%>”结尾处

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

也许 ?