Tag: gruntjs

如何设置Gruntfile.js来监视SASS(指南针)和JS

我新使用gruntjs和nodejs。 我想知道如何设置gruntfile,以便使用watch观看sass文件和js文件编译。 这是我迄今为止: module.exports = function ( grunt ) { "use strict"; require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks); grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), compass: { dist: { options: { config: 'config.rb', watch: true } } } }); grunt.registerTask('default', []); }; 任何帮助都感激不尽。 谢谢!

Grunt环境variables不会被设置,直到所有的任务加载

我在我的项目中使用npm模块grunt env和load-grunt-config 。 grunt env为你处理环境variables,而load-grunt-config处理,为你加载gruntconfiguration。 你可以把你的任务放到其他文件中,然后load-grunt-config将它们捆绑在一起,并且有很多的负载并且为你消耗。 您也可以创build一个aliases.js文件,将您想要合并为一个任务的任务一个接一个地运行。 它与原始Gruntfile.js的grunt.registerTask任务类似。 我把所有的grunt任务放在一个单独的grunt/文件夹下,并且在主Gruntfile没有额外的子文件夹,正如Github上的load-grunt-config README.md所build议的那样。 这是我瘦身的Gruntfile : module.exports = function(grunt) { 'use strict'; require('time-grunt')(grunt); // function & property declarations grunt.initConfig({ pkg: grunt.file.readJSON('package.json') }); require('load-grunt-config')(grunt, { init: true, loadGruntConfig: { scope: 'devDependencies', pattern: ['grunt-*', 'time-grunt'] } }); }; 从理论上讲,将所有这些文件设置为load-grunt-config加载的正确方式应该与只有一个Gruntfile.js 。 不过,我似乎遇到了一点麻烦。 似乎在env任务下设置的环境variables不会为随后的grunt任务设置,而是由时间node处理其任务(在本例中为express服务器)设置。 grunt env任务: module.exports = { // environment variable values […]

如何将-harmony节点标志添加到grunt-express

我正在用grunt-express做本地开发。 这里是我的GruntFile.js var path = require('path'); module.exports = function(grunt){ grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify:{ options:{ banner:'/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' } }, express:{ server:{ options:{ debug:true, server: path.resolve('app.js') } } }, env : { options:{ }, dev : { NODE_ENV : 'development' }, prod : { NODE_ENV : 'production' } }, mochaTest:{ test:{ […]

如何修改基于文件更改的grunt watch任务?

我正在编写一个node.js程序,它将监视一个充满大量(300小时)的scss项目的目录。 Grunt-watch(无论是通过节点模块运行还是独立运行,无论哪种方式运行)都将被configuration,以便每当scss文件发生更改时,都会使用指南针进行编译,输出文件将移至单独的目录,例如: ./1234/style.scss已更改>> grunt-watch运行grunt-compass >> /foo/bar/baz/1234/style.css更新 该文件所在的项目目录显然是非常重要的(如果grunt-compass将所有已编译的文件发送到同一个目录,那么它们就会变得混乱而不可用,而且这个混乱的自动化将是无意义的)。 我为了确保所有的文件被路由到正确的地方,我每次更新css文件时都会dynamic地改变grunt-compass设置。 示例gruntfile: module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), watch: { files: './*/*.scss', tasks: ['compass'] }, compass: { origin:{ options: { //temportary settings to be changed later sassDir: './', cssDir: './bar', specify: './foo.scss' } } } }); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-compass'); grunt.event.on('watch', function(action, filepath, target) { var path = require('path'); […]

Gruntjs:致命错误:getaddrinfo ENOTFOUND

我应该指出,我是没有经验的用户第一,我的问题是, '主机名'属性不能有任何值分配除空string(''),'0.0.0.0'和'本地主机'。 我得到: 致命错误:getaddrinfo ENOTFOUND 。 我究竟做错了什么? 如果得到它的权利,我可以改变我通常在地址栏中input的地址,所以,而不是'localhost'我可以键入'example.com'或类似的东西。 正如我上面提到的,我已经指定了不同的值,但只有三个已经工作。 所以为什么这个'*'不起作用。 这是我的Gruntfile.js : module.exports = function( grunt ) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), watch: { scripts: { files: ['*.js'], options: { livereload: true } }, markup: { files: ['*.html'], options: { livereload: true } }, stylesheets: { files: ['*.css'], options: { livereload: true } } }, connect: […]

如何用grunt来缩小JSON文本文件?

我需要使用Grunt / grunt-contrib-uglify来缩小一组JSON文件(语言文件): grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { build: { src: 'src/main/app/resources/locales/*/*.json', dest: 'target/resources/locales/*/*.json' } } }); 我得到的是: Files: src/main/app/resources/locales/en/messages.json -> target/*/*.json Minifying with UglifyJS…Reading src/main/app/resources/locales/en/messages.json…OK >> Uglifying source "src/main/app/resources/locales/en/messages.json" failed. Warning: Uglification failed. Use –force to continue. 我开始怀疑,uglify是纯粹的JSON文件,还是仅适用于JavaScript源文件? JSON文件肯定是格式良好的,它以非最小化的forms在应用程序中运行。

错误:找不到模块npm-shrinkwrap

设置引导与咕噜声。 获取以下错误: 找不到模块npm-shrinkwrap 尝试npm安装shrinkwrap,仍然得到相同的错误。

如何使用node-inspector,Windows 7debugging带有断点的Gruntfile?

所以我花了几天的时间试图让这个没有运气的工作。 我发现的大多数解决scheme似乎对于debugging节点应用程序都是“好的”。 但我没有太多的运气debugging咕噜站在独立。 我希望能够在我的gruntfile中设置断点,并通过浏览器或IDE浏览代码。 我已经尝试了以下内容: 使用intelliJ IDE进行debugging使用Grunt控制台 ( 处理结束,退出代码6 ) 使用Nodeeclipse进行debugging ( 这种工作方式没问题,但是不会在eclipse中设置断点,不太直观 ) 使用node-inspector进行debugging ( 这也是一些工作,我可以在chrome中使用F11和F10,但最终它只是崩溃,使用F8跳到break point永远不会工作。 错误信息使用节点检查器 所以目前节点检查员觉得它已经让我接近我想要的。 为了达到这里我做了以下几点: 从我的grunt目录中运行以下命令: grunt node-inspector node –debug-brk Gruntfile.js 然后从那里我去了localhost:8080/debug?port=5858来debugging我的Gruntfile.js。 但就像我上面提到的,只要我打F8跳到断点它崩溃与上述错误。 有没有人有任何成功使用这种方法来尝试debuggingGruntfile? 从我的search工作到目前为止,我还没有find一个非常有据可查的方法来做到这一点。 所以希望这将是对未来用户有用或有益的信息。 另外我正在使用Windows 7的方式。 提前致谢。 更新: 我已经尝试过以下build议的@dylants没有运气。 在位于C:\Users\khollenbeck\AppData\Roaming\npm Windows计算机上findgrunt.cmd文件。 打开grunt.cmd文件,发现以下…. 这导致我包含一个名为grunt的文件的C:\Users\khollenbeck\AppData\Roaming\npm\node_modules\grunt-cli\bin 。 从那里的文件的顶部。 我将这个代码#!/usr/bin/env node改为#!/usr/bin/env node –debug-brk 在做这个命令node-inspector C:\path\to\gruntfile grunt我得到了以下。 Node Inspector v0.7.3 Visit http://localhost:8080/debug?port=5858 […]

自定义的咕task任务命名约定

有没有关于命名包含多个单词的自定义任务的任何约定? 例如: grunt-json-schema grunt插件有json_schema任务 。 一个名称包含破折号( – ),另一个名称包含下划线( _ )。 显然,dashed-name不能用作JavaScript对象键: grunt.initConfig({ json-schema: { // WON'T work 他们必须用引号括起来: grunt.initConfig({ 'json-schema': { // will work 我检查了所有官方插件( grunt-contrib-* ),但它们都只包含一个单词。 造成这个问题的动机很简单:我只是想遵循惯例。

如何使用Grunt在Visual Studio 2013中debuggingAngularJS应用程序?

我目前正在尝试debugging使用Visual Studio 2013编写的AngularJS应用程序。我有最近发布的Node.js工具安装。 该应用程序使用Yeoman / Bower / Grunt脚手架,并使用命令行grunt serve命令打包并启动localhost web服务器。 如何从Visual Studio 2013启用debugging? 我是否必须重视stream程,还是可以将它与VS2013中值得信赖的F5连接起来,还是甚至有可能?