javascript - 使用 Grunt 检索 html 主体的内容

标签 javascript gruntjs

是否有一个 grunt 任务可以抓取 html 正文的内容并将其放入单独的文件中?

<html>
    <body>
        <h1>Grab this</h1>
        <h2>And this</h2>
    </body>
</html>

最佳答案

您可以使用 Grunt 的“复制文件部分”来选择正文。

文档在这里。 https://www.npmjs.com/package/grunt-copy-part-of-file

例如

grunt.initConfig({
    copy_part_of_file: {
        simple_replace_scripts: {
            options: {
                sourceFileStartPattern: '<body>',
                sourceFileEndPattern: '</body>',
                destinationFileStartPattern: '',
                destinationFileEndPattern: ''
            },
            files: {
                'test/fixtures/simple-destination.html': ['test/fixtures/simple-source.html']
            }
        }
    },
})

关于javascript - 使用 Grunt 检索 html 主体的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28054129/

相关文章:

javascript - 如何摆脱织物中 Canvas 拖动时的蓝色突出显示框

javascript - jQuery - $.extend 不返回预期的函数

mysql - grunt shell 创建数据库

javascript - Terser 不提供缩小文件

html - 运行 grunt dist 后标题未正确对齐

node.js - EJS 在 gruntfile 中转义

javascript - 如何从数组数组中获取整数?

javascript - 如何为 Angular 2+ 设置本地存储的超时?

javascript - 获取为 flot.js 呈现的图表中的最小值

javascript - Grunt 设置任务选项并使用新值运行该任务