gruntjs - Grunt watch 不编译所有文件
问题描述
我的 grunt watch 应该在保存时再次构建所有文件(我还没有“更新”的一个设置),但它并没有完成所有 .dust 文件?它正在跳过文件。例如,我有几个带有“overview.dust”的目录,当我现在保存它们时,它不会为保存的那个更新/构建 .html 文件,而是为目录中的其他 .dust 文件更新/构建。
我的 gruntfile.js:
module.exports = function(grunt) {
// empty init config
grunt.initConfig({});
// import task configs from grunt folder
grunt.loadTasks("grunt");
grunt.registerTask("test", ["copy", "concat:tests", "qunit"]);
// register detault task
grunt.registerTask("main", ["less", "concat", "dusthtml"]);
grunt.registerTask("default", ["main", "watch"])
// run in Dev mode
grunt.registerTask("dev", ["clean", "default"]);
// run Prod Build
grunt.registerTask("prod", ["main"]);
};
我的 package.json 文件:
{
"name": "dust",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"grunt-contrib-clean": "^1.0.0"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-concat": "^1.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-less": "^2.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-dust-html": "^0.3.0",
"grunt-jscs": "^2.7.0",
"grunt-sass": "^1.1.0"
}
}
我的dust-html.js 文件:
var path = require("path");
module.exports = function(grunt) {
var dustFiles = {};
grunt.file.expand("src/template/**/*.dust").forEach(function(file) {
var shortName = path.basename(file, ".dust"),
taskName = shortName.replace(/\W/g, ""),
context = grunt.file.expand("src/template/data/**/" + shortName + "*.json")[0],
distPath = path.dirname(file).replace(/^src[\/\\]template/, "");
if (!context) {
context = "src/template/data/serverController.json";
}
dustFiles[taskName] = {
src: file,
dest: "dist" + distPath + "/" + shortName + ".html",
options: {
basePath: "./src/",
partialsDir: "./src/",
context: context,
whitespace: true
}
};
});
grunt.config.set("dusthtml", dustFiles);
grunt.loadNpmTasks("grunt-dust-html");
};
提前感谢您提供的任何指导/帮助。我不是过分关注开发人员,所以请帮助解释解释的答案。:)
解决方案
推荐阅读
- php - php:在未定义的变量上回显 isset 不返回任何内容而不是零
- python - 如何从 PDF 生成带有表格标签的 HTML?
- python - 在 model.fit() 中调用时,如何修改 train_step 以支持验证集?
- c# - 将平面对象列表转换为c#中的嵌套对象列表
- installation - SelectDirBrowseLabel 中的新行被目录编辑框剪切
- php - 重写 wordpress sanitize_user 函数以禁止用户名注册表中的空格
- excel - Excel VBA 将图表导出到带有书签的单词
- javascript - nextElementSibling 未捕获 CSS 样式
- php - 如何在 Laravel 上访问 1 个 IP 的域或子域?
- automation - 使用 Gatling 通过变量传递 Bearer 令牌