拆分一个 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 is not defined
尽管我有以下设置:
aliases.yaml
default:
- 'jade'
- 'sass'
- 'watch
文件夹结构
/grunt
aliases.yaml
jade.js
sass.js
watch.js
Gruntfile.js
module.exports = function(grunt) {
// load grunt config
require('load-grunt-config')(grunt);
};
我已经安装了 load-grunt-config 和 load-grunt-tasks。
如果你想在你的配置中使用 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"
} ]
}
}
}
我的 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 is not defined
尽管我有以下设置:
aliases.yaml
default:
- 'jade'
- 'sass'
- 'watch
文件夹结构
/grunt
aliases.yaml
jade.js
sass.js
watch.js
Gruntfile.js
module.exports = function(grunt) {
// load grunt config
require('load-grunt-config')(grunt);
};
我已经安装了 load-grunt-config 和 load-grunt-tasks。
如果你想在你的配置中使用 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"
} ]
}
}
}