拆分gruntfile(splitting up a gruntfile)
我在我的gruntfile中有这个任务:
jade: { compile: { options: { client: false, pretty: true, data: { section: grunt.file.readJSON('json/section.json') } }, files: [ { cwd: "app/views", src: "**/*.jade", dest: "build/templates", expand: true, ext: ".html" } ] } }但是,当我将这个片段添加到js文件jade.js时,如下所示:
module.exports = {
compile: { options: { client: false, pretty: true, data: { section: grunt.file.readJSON('json/section.json') } }, files: [ { cwd: "app/views", src: "**/*.jade", dest: "build/templates", expand: true, ext: ".html" } ] }}
我得到错误ReferenceError:未定义grunt
虽然我有以下设置:
aliases.yaml
default: - 'jade' - 'sass' - 'watch文件结构
/grunt aliases.yaml jade.js sass.js watch.jsGruntfile.js
module.exports = function(grunt) { // load grunt config require('load-grunt-config')(grunt); };我安装了load-grunt-config和load-grunt-tasks。
I have this task in my gruntfile:
jade: { compile: { options: { client: false, pretty: true, data: { section: grunt.file.readJSON('json/section.json') } }, files: [ { cwd: "app/views", src: "**/*.jade", dest: "build/templates", expand: true, ext: ".html" } ] } }However when I add this snippet to a js file jade.js like so:
module.exports = {
compile: { options: { client: false, pretty: true, data: { section: grunt.file.readJSON('json/section.json') } }, files: [ { cwd: "app/views", src: "**/*.jade", dest: "build/templates", expand: true, ext: ".html" } ] }}
I get the error ReferenceError: grunt is not defined
although I have the following setup:
aliases.yaml
default: - 'jade' - 'sass' - 'watchFOLDER STRUCTURE
/grunt aliases.yaml jade.js sass.js watch.jsGruntfile.js
module.exports = function(grunt) { // load grunt config require('load-grunt-config')(grunt); };I have load-grunt-config and load-grunt-tasks both installed.
最满意答案
如果要在配置中使用grunt ,则必须使用jade.js文件的函数形式:
module.exports = function (grunt, options) { return { compile: { options: { client: false, pretty: true, data: { section: grunt.file.readJSON('json/section.json') } }, files: [ { cwd: "app/views", src: "**/*.jade", dest: "build/templates", expand: true, ext: ".html" } ] } } }If you want to use grunt in your config, you have to use the function form for the jade.js file:
module.exports = function (grunt, options) { return { compile: { options: { client: false, pretty: true, data: { section: grunt.file.readJSON('json/section.json') } }, files: [ { cwd: "app/views", src: "**/*.jade", dest: "build/templates", expand: true, ext: ".html" } ] } } }更多推荐
发布评论