[英]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.