【发布时间】:2014-04-03 17:08:26
【问题描述】:
目前我正在尝试改进构建网络应用程序的工作流程。 安装 Yeoman 后,“grunt”命令为我提供了一种合并和缩小我的 javascript 文件的好方法。 我的 main.js 文件是从很多咖啡脚本文件中生成的,我之前是手动完成的。由于文件依赖性,我不使用编译coffeescript的集成方式。 (没关系)
但问题来了: 当我现在尝试运行“grunt”时,它会给我生成的 js 文件中的“lint”错误,例如:
line 3 col 3 Missing "use strict" statement.
line 3 col 3 Expected 'var' to have an indentation at 5 instead at 3.
line 4 col 102 Expected '{' and instead saw 'child'.
line 4 col 233 A constructor name should start with an uppercase letter.
Warning: Task "jshint:all" failed. Use --force to continue.
如果我 --force 让它继续,输出 dest 文件夹中的 main.js 仍然是空的
我能做什么? 我认为编译后的 coffeescript 是“lint ready”的 javascript?
要编译我的咖啡脚本文件,我使用“rehab”: https://www.npmjs.org/package/rehab
它为我提供了这个 Cakefile:
{exec, spawn} = require 'child_process'
Rehab = require 'rehab'
build = ->
console.log "Building project from src/*.coffee to app/scripts/main.js"
files = new Rehab().process 'src'
files = files.join " "
join_to_single_file = "--join app/scripts/main.js"
compile_from_files = "--compile #{files}"
exec "coffee #{join_to_single_file} #{compile_from_files}", (err, stdout, stderr) ->
throw err if err
task 'build', 'Build coffee2js using Rehab', sbuild = ->
build()
更新:
如果我理解正确,我的 main.js 文件将永远不会通过 jshint,所以我必须删除 yeoman / grunt 的检查才能更进一步?我从 gruntfile.js 中删除了这一行:
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: [
'Gruntfile.js',
// removed '<%= yeoman.app %>/scripts/{,*/}*.js',
'!<%= yeoman.app %>/scripts/vendor/*',
'test/spec/{,*/}*.js'
]
},
现在如果运行“grunt”我没有错误,但我在 dest 文件夹中的输出仍然包含一个空的 main.js :(
【问题讨论】:
-
对编译后的 CoffeeScript 进行 lint 检查是没有意义的。您可以调整您的设置以适应 CoffeeScript 生成的内容,但它不会让您获得任何结果,因为 CoffeeScript 确实总是生成适合该模式的代码。
标签: javascript coffeescript gruntjs yeoman