我安装了node.js并使用npm install -g grunt我设法安装grunt文件.这个过程一直运行到现在,但我运行grunt命令它给我抛出批处理文件错误.可能是什么原因?我确实安装了phonegap,它能够轻松找到/设置路径,但在GRUNT不工作的地方,请帮忙.
我正在使用load-grunt-config和grunt-contrib-copy,我正在尝试使用'process'选项来替换一些模板标签.
我知道替换模板标签是可能的(来自grunt-contrib-copy文档),但我无法让它工作.我要做的是将<%= init.project.name %>"style.css"中的字符串替换为同名的模板变量(由用户使用grunt-prompt输入).
在副本上我想要grunt用style.css文件中的模板变量替换它在内存中的值.但是当我使用下面的代码时,它不会这样做.有谁知道我做错了什么?
Grunt复制任务
// -------------------------------------
// Grunt copy
// -------------------------------------
module.exports = {
// ----- Copy files for initialization (selected with grunt prompt) ----- //
init: {
files: [{
cwd: 'init/php/templates',
src: '<%= init.php.templates %>',
dest: 'src/php/templates',
expand: true
}, {
cwd: 'init/php/includes',
src: '<%= init.php.includes %>',
dest: 'src/php/includes',
expand: true
}, {
cwd: 'init/js',
src: '<%= init.scripts %>',
dest: 'src/js',
expand: true
}, {
cwd: 'init/css',
src: 'style.css',
dest: 'src/css', …Run Code Online (Sandbox Code Playgroud) 尝试开始玩Famo.us示例.我按照Github页面上的步骤操作,当我执行"grunt serve"时,浏览器打开但出现以下错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:1337/lib/famous-polyfills/functionPrototypeBind.js
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:1337/lib/famous-polyfills/classList.js
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:1337/lib/famous/core/famous.css
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:1337/lib/famous-polyfills/requestAnimationFrame.js
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:1337/lib/requirejs/require.js
Run Code Online (Sandbox Code Playgroud)
使用Chrome在Windows 7上运行它.不知道怎么解决这个问题?
当我运行grunt serve或grunt autoprefixer发生警告但没有提及文件路径时,仅提及行和列。
$ grunt autoprefixer
Running "autoprefixer:dist" (autoprefixer) task
Warning: Can't parse CSS: property missing value near line 12:21 Use --force to continue.
Aborted due to warnings.
Execution Time (2014-05-05 20:24:50 UTC)
loading tasks 3ms ??????????? 13%
autoprefixer:dist 19ms ????????????????????????????????????????????????????????????????????? 83%
Total 23ms
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
谢谢大家!
我正在尝试grunt使用一个简单的任务grunt-contrib-copy,但它在到达复制任务时立即死亡,并显示以下消息:
运行"copy:main"(复制)任务
警告:EPERM,不允许操作'C:\ Documents and Settings'使用--force继续
因警告而中止
我在跑步:
C:\Documents and Settings不存在)C:\nodejs)我在两个C:\nodejs和我的项目文件夹(C:\Users\myusername\Documents\Programming\myprojectname没有空格或括号)中对"文档和设置"进行了全文搜索,但没有匹配.
我的copy任务定义是:
copy: {
main: {
files: [
{expand: true, cwd: 'src/core', src: '/**', dest: 'src/chrome/'},
{expand: true, cwd: 'src/core', src: '/**', dest: 'src/firefox/'}
]
}
},
Run Code Online (Sandbox Code Playgroud)
可能导致此错误的原因是什么?
我使用了javascript任务运行程序Grunt来测试使用grunt-uncss从单个页面中删除未使用的CSS样式.这很好用,但是我试图确定在大型动态框架上使用它的最佳方法,例如Magento(它有数千个文件).
任何人都可以确定使用Grunt和Magento的最佳方法,而无需确定单个配置的负载吗?对此有任何建议将不胜感激.
我正在使用grunt-svgstore来合并SVG文件.有一个名为'cleanup'的选项(https://github.com/FWeinb/grunt-svgstore#optionscleanup)应该:
清理所有可能危及以后基于样式表的着色(填充)的内联样式定义.
但是,我的似乎没有用.其余的运行正常,我得到前缀和viewBox和文件创建.这只是清理似乎不起作用.我在这里得到了语法错误(来自我的Gruntfile.js)?
svgstore: {
options: {
prefix: 'icon-',
cleanup: true,
svg: {
viewBox: '0 0 32 32',
class: 'is-hidden'
}
},
default: {
files: {
'svg/svg-sprite.svg': ['svg/*.svg']
}
}
}
Run Code Online (Sandbox Code Playgroud) 我最近将我的Ruby更新为v1.9.3并更新了sass和指南针.现在,当我运行grunt-contrib-scss任务时,我收到错误:
NoMethodError: undefined method `<<' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
我不是指南针和scss的专家,所以我不知道发生了什么.
我有一个空文件夹,我在其中创建了一个package.json文件,其中包含:
{
"name":"sample project",
"version":"0.0.1",
"title":"My grunt App",
"homepage":"http://gruntjs.com"
}
Run Code Online (Sandbox Code Playgroud)
稍后在同一个文件夹中,我试图运行此命令:
npm install grunt --save-dev
但我得到这样的错误:根本无法安装grunt
D:\grunt2>npm install grunt --save-dev
npm ERR! Error: Invalid name: "sample project"
npm ERR! at ensureValidName (C:\Program Files (x86)\nodejs\node_modules\npm\
node_modules\read-package-json\node_modules\normalize-package-data\lib\fixer.js:
300:15)
npm ERR! at Object.module.exports.fixNameField (C:\Program Files (x86)\nodej
s\node_modules\npm\node_modules\read-package-json\node_modules\normalize-package
-data\lib\fixer.js:204:5)
npm ERR! at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\read
-package-json\node_modules\normalize-package-data\lib\normalize.js:30:38
npm ERR! at Array.forEach (native)
npm ERR! at normalize (C:\Program Files (x86)\nodejs\node_modules\npm\node_m
odules\read-package-json\node_modules\normalize-package-data\lib\normalize.js:29
:15)
npm ERR! at final (C:\Program Files (x86)\nodejs\node_modules\npm\node_modul
es\read-package-json\read-json.js:342:33)
npm ERR! at then …Run Code Online (Sandbox Code Playgroud) 我尝试config.js使用grunt-template模块创建文件,但它没有按预期创建任何文件.
我已经安装了grunt-template npm install grunt-template --save-dev
当我运行时,grunt build我希望创建一个配置文件,其中包含在模板配置中设置的适当内容.我在下面添加了gruntfile,config.js.tpl和grunt构建结果.会出现什么问题?
Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
....
'template': {
'config': {
'options': {
'data': {
'backend': '127.0.0.1:8000'
}
}
},
'files': {
'config.js': ['config.js.tpl']
}
}
}
grunt.loadNpmTasks('grunt-template');
grunt.registerTask('build', [
'template'
]);
}
Run Code Online (Sandbox Code Playgroud)
config.js.tpl
angular.module('report-constants',[])
.constant('env', {
'backend': ''
});
Run Code Online (Sandbox Code Playgroud)
grunt构建结果
执行时间(2015-01-14 11:33:59 UTC)加载任务4ms▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ ▇▇▇▇44%模板:配置3ms▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇33%模板:文件1ms▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ ▇▇11%总共9ms