Gil*_*leg 8 javascript compilation gruntjs grunt-contrib-watch pug
使用grunt-contrib-watch
建议仅在此处编译已更改文件的版本:https://github.com/gruntjs/grunt-contrib-watch#compiling-files-as-needed
var changedFiles = Object.create(null);
var onChange = grunt.util._.debounce(function() {
grunt.config('jshint.all.src', Object.keys(changedFiles));
changedFiles = Object.create(null);
}, 200);
grunt.event.on('watch', function(action, filepath) {
changedFiles[filepath] = action;
onChange();
});
Run Code Online (Sandbox Code Playgroud)
这工作正常(再次我在这里写的变体:https://gist.github.com/pgilad/6897875)
问题是include
在Jade模板中使用时,意味着你要包含其他Jade模板以构建完整的html文件.
使用单数解决方案进行编译不起作用,因为如果.jade
正在使用include current_working_jade.jade
的文件是嵌入式的- 包含文件将不会被重新编译.
除了jade
从头开始编译所有文件之外,还有其他解决方法吗?每次有大约60个大型玉文件要编译时,这会导致问题.
我能想到的唯一可能的解决方案是在外部或使用目录映射jade模板依赖项,但我不知道有哪些工具/插件可以做到这一点......
在开始制作可以生成某种玉石的脚手架后,sourcemap
我发现了这个伟大的项目,它已经解决了这个问题:
用法如下:
npm install jade-inheritance --save-dev
您想从玉石中获取依赖文件列表的位置:
var JadeInheritance = require('jade-inheritance');
var inheritance = new JadeInheritance(file, basedirname, {basedir:basedirname});
然后当你想获取文件时:
depenedentFiles = inheritance.files;
该项目还演示了如何应用该概念,grunt.watch
以便仅编译已更改的jade
文件及其依赖项,这正是我所需要的:
归档时间: |
|
查看次数: |
1441 次 |
最近记录: |