拆分gruntfile(splitting up a gruntfile)

编程入门 行业动态 更新时间:2024-10-28 00:24:35
拆分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.js

Gruntfile.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' - 'watch

FOLDER STRUCTURE

/grunt aliases.yaml jade.js sass.js watch.js

Gruntfile.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" } ] } } }

更多推荐

本文发布于:2023-07-22 12:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219892.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:gruntfile   splitting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!