我目前正在为 gruntjs 设置自动构建脚本(使用 require.js )驱动的项目。因此我想运行 jslint/jshint在使用 r.js 连接和缩小所有必需文件之前。由于js文件夹包含很多我不想lint的开发文件,我不能只将js/**/*.js
传递给JSLint。我的第一个想法是使用 optimizer: 'none'
运行 r.js,对连接的文件进行 lint,然后将其缩小,但这不是一个选项,原因有二。首先它将包括 vendor 库我不想 lint,然后找到有错误的行,找到它的类,在 dev 文件夹中找到合适的 js 文件,在那里修复它,再次运行 r.js 最后 lint 它再次,这对我们的工作流程来说很麻烦。所以我正在寻找一种可能性,将 linting 连接到 r.js 优化器进程中,或者至少以某种方式获得 requirejs 依赖树的列表,我可以解析并将其传递给 lint。或者任何适用于自动化流程的解决方案,您都会想到。
最佳答案
先 Lint,后编译。只需具体说明您想要 lint 的文件并使用 !忽略特定文件的前缀:
grunt.initConfig({
lint: {
// Specify which files to lint and which to ignore
all: ['js/src/*.js', '!js/src/notthisfile.js']
},
requirejs: {
compile: {
options: {
baseUrl: 'js/src',
name: 'project',
out: 'js/scripts.js'
}
}
}
});
// Load the grunt-contrib-requirejs module.
// Do `npm install grunt-contrib-requirejs` first
grunt.loadNpmTasks('grunt-contrib-requirejs');
// Our default task (just running grunt) will
// lint first then compile
grunt.registerTask('default', ['lint', 'requirejs']);
关于javascript - 将 JSLint/Hint 与 requirejs 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12937091/