简体   繁体   English

在src /和dist /之间同步删除与.pug文件相对应的.html文件

[英]Sync delete .html files corresponding to .pug files between src/ and dist/

I use grunt-contrib-pug to compile my .pug files from src/ and distribute the corresponding .html files to dist/. 我使用grunt-contrib- pug从src /编译我的.pug文件,并将相应的.html文件分发到dist /。 Here is my pug-task config (written in .coffee): 这是我的哈巴狗任务配置(用.coffee编写):

compile:
    options: pretty: false
    files: [ {
        expand: true
        cwd: 'src/'
        src: [ '**/*.pug', '!includes/**' ]
        dest: 'dist/'
        ext: '.html'
    } ]

When I delete a .pug file from src/, is there any way to synchronize delete corresponding html files in dist/? 当我从src /中删除.pug文件时,是否有任何方法可以同步删除dist /中的相应html文件? I know you can use grunt-contrib-clean followed by compiling the pug files again, but this is not time efficient when working with a large codebase. 我知道您可以先使用grunt-contrib-clean,然后再次编译pug文件,但是在使用大型代码库时,这不是省时的。

As referenced by I-LOVE-2-REVIVE , I looked further into Grunt's file API , and on that basis, this is the solution I came up with: 正如I-LOVE-2-REVIVE所引用的那样,我进一步研究了Grunt的文件API ,在此基础上,我提出了以下解决方案:

grunt.event.on 'watch', (action, filepath, target) ->
  if action == 'deleted' && /pug/.test(filepath)

     file = 'dist' + filepath.slice(3, -3) + 'html'
     grunt.file.delete file
     # Log deleted files
     grunt.log.write '\n' + filepath + ' deleted > ' + file + ' deleted.\n'

It works great! 效果很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果您从“ src”中删除原型,如何从“ dist”文件夹中自动删除文件? - How to auto delete files from the “dist” folder if you delete prototype from “src”? 在 html 和 javascript 中设置文件 src 有什么区别 - what is the difference between setting a files src in html vs javascript 如何使用Webpack将脚本文件从src复制到dist - How to copy script files from src to dist using webpack 触发事件后,如何在HTML文件及其相应的js和css文件之间转换? - How do I transition between HTML files and their corresponding js and css files after an event is triggered? 如何使用 Pug 将 Markdown 文件的目录转换为 HTML 页面? - How to use Pug to convert a directory of Markdown files into HTML pages? Webpack 可以从 SCSS 和 Pug 构建多个 HTML 文件吗? - Can Webpack build multiple HTML files from SCSS and Pug? dist文件中的错误Angular 2 - Error in dist files Angular 2 dist /文件夹中的JS文件与root文件夹中的JS文件有什么区别? - What is the difference between JS files in dist/ folder and the one in root? 避免在我的HTML页面中使用多个src文件 - Avoid multiple src files in my html page 如何将“dist”文件夹转换为其源“src”和其他依赖文件夹和文件 - how to convert "dist" folder to its source "src" and other dependence folders and files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM