grunt: how to replace paths in html file using grunt task

前端 未结 2 1207
别那么骄傲
别那么骄傲 2020-12-13 22:13

inside my grunt configuration if have a variable which defines a directory which contains a css file. Now I would like to configure a grunt task which insert the value of th

相关标签:
2条回答
  • 2020-12-13 23:00

    I think the grunt-replace package is what you're looking for. You can read an external file and use its value in the patterns definitions like so:

    replace: {
      dist: {
        options: {
          patterns: [
            {
              match: '<% pathToCss %>',
              replacement: '<%= grunt.file.read("conf/assets-dir.txt") %>'
            }
          ]
        }
      }
    }
    
    0 讨论(0)
  • 2020-12-13 23:09

    I just found out that it can be done with grunt.template as follows:

    template: {
            options: {
                data: {
                    pathToCss: './css'
                }
            },
            demo: {
                files: [
                    { '<%= ./output/index.html':  ['<%= ./input/template.html'] }
                ]
            }
        },
    

    And in the input file (template.html) you define 'pathToCss' as follows:

    <link rel="stylesheet" href="../../<%- pathToCss %>/styles.css">
    

    However, if I look at the documentation, I don't see where this is documentated!

    0 讨论(0)
提交回复
热议问题