【问题标题】:Grunt bake file include cannot read fileGrunt 烘焙文件包含无法读取文件
【发布时间】:2021-07-23 05:58:18
【问题描述】:

我的根目录中有以下 index.html

当我运行 grunt 时,我收到以下错误:

Verifying property bake.my_target exists in config...OK
Files: index.html -> dist/index.html
Options: content="content.json", section=null, semanticIf=false, basePath="", transforms={}, parsePattern={}, variableParsePattern={}, removeUndefined
Reading content.json...OK
Parsing content.json...OK
Reading index.html...OK
Reading /includes/test.html...ERROR
Warning: Unable to read "/includes/test.html" file (Error code: ENOENT). Use --force to continue.

这是我的 gruntfile.js:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      build: {
        src: 'src/<%= pkg.name %>.js',
        dest: 'build/<%= pkg.name %>.min.js'
      }
    },
    bake: {
      my_target: {
        options: {
          content: "content.json"
        },
        files: {
          "dist/index.html": "index.html"
        }
      }
    }
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks( "grunt-bake" );

  // Default task(s).
  grunt.registerTask('default', ['uglify', 'bake']);

};

我做错了什么。我只是关注了这个链接中的文档:https://www.npmjs.com/package/grunt-bake

【问题讨论】:

    标签: html npm gruntjs


    【解决方案1】:

    如果烘焙文件放在文件夹的根目录下,grunt-bake 似乎存在包含路径解析的错误。尝试将您的 index.html 放到某个文件夹中,例如 'src/index.html' - 这对我有用(浪费了几个小时后)。

    grunt-bake 的源代码包含这一行,因此它总是将 '/' 放在 "include" 文件路径中 - 我想这就是它不起作用的原因根目录下的文件:

    directory( filePath ) + "/" + includePath
    

    【讨论】:

      猜你喜欢
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      • 2012-01-12
      • 1970-01-01
      • 2011-08-28
      • 1970-01-01
      • 2020-08-25
      • 2011-12-18
      相关资源
      最近更新 更多