私は現在、require.js主導プロジェクトの自動ビルドスクリプト(gruntjs)を設定しています。そのため、すべての必要なファイルについてjslint/jshintを実行してから、r.jsを連結して縮小します。 jsフォルダにはたくさんの開発ファイルが入っているので、lintを使いたくないので、js/**/*.js
をJSLintに渡すことはできません。私の最初の考えは、optimizer: 'none'
でr.jsを実行し、連結したファイルをlintしてからそれを小さくすることでしたが、これは2つの理由からオプションではありません。まず、ベンダーのlibsが含まれています。私は、lintと2番目のエラーを見つけて、そのクラスを見つけ、devフォルダ内の適切なjsファイルを見つけてそこに修正し、r.jsをもう一度実行して、もう一度、私たちのワークフローのために非常に面倒です。ですから、lintをr.jsオプティマイザプロセスに接続するか、少なくとも何らかの方法でrequirejs依存関係ツリーのリストを取得し、それを解析してlintに渡すことができるかどうかを探しています。あるいは、自動化されたプロセスのために実用的な解決策があれば、それを思いつくでしょう。JSLint/Hint with requirejsを使用
答えて
この回答はバイパスのグランツですが、あなたがしたいことでうまくいくはずです。 r.jsを見て、ロードされているさまざまなモジュールへのパスを受け取り、モジュール名をインターセプトし、r.jsがロードしてモジュールをコンパイルしている間にファイルをlintする関数をオーバーライドしようとします。私はそうのようにそれをやった:
var requirejs = require('requirejs');
var options = {/*r.js options as JSON*/};
var oldNewContext = requirejs.s.newContext;
requirejs.s.newContext = function(){
var context = oldNewContext.apply(this, arguments);
var oldLoad = context.Module.prototype.load;
context.Module.prototype.load = function(){
var module = oldLoad.apply(this, arguments);
if(/\.js$/.test(this.map.url) && !/^empty:/.test(this.map.url))
console.log(this.map.url);
return module;
}
return context;
}
requirejs.optimize(options)
を次に、あなたがあなたのモジュール上requirejs.optimize実行すると、コンソールにログインし、すべての非空のJavaScriptのURLを取得する必要があります。コンソールにログを記録する代わりに、URLを使用してファイルをlintすることができます。
これはまさに私が探していたものだと思う。明日テストするつもりだ。 –
最初に、コンパイルしてください。あなたが糸くずにしたいと思っているファイルを特定して使用してください!接頭辞は特定のファイルを無視します:
2つのファイル(main.jsとgrunt)を維持しなければならないので、間違いなく良い方法ですが、IMHOは非常に繰り返します。 ...あなたの答えはいつもおかげさまです。 –
私はr.jsのメソッドをオーバーライドしていない好む、またはあなたが特定のバージョンに不要な依存関係を作成します(あなたのコードが変更をr.jsすべき更新する必要があります)
これは、私が使用したコードです同じ目的で、requireのonBuildRead関数とjavascriptのオブジェクトが参照渡しされるという事実を利用しています。私はrequireビルドを最初に実行した後、jsファイルのソースをリントするようにします。
欠点は、ビルドが完了した後にリントすることです。私のセットアップには問題はありません。代わりにlint
タスクを使用しての
module.exports = function(grunt) {
var jsHintOptions = {
options: {
curly: true,
eqeqeq: true,
eqnull: true,
browser: true,
globals: {
jQuery: true
}
},
all: [] // <--- note this is empty! We'll fill it up as we read require dependencies
};
var requirejsOptions = {
compile: {
options: {
paths: {
"jquery": "empty:"
},
baseUrl: "./",
name: "src/mypackage/main",
mainConfigFile: "src/mypackage/main.js",
out: 'build/mypackage/main.js',
onBuildRead: function (moduleName, path, contents) {
jsHintOptions.all.push(path); // <-- here we populate the jshint path array
return contents;
}
}
}
};
grunt.initConfig({
pkg: grunt.file.readJSON('packages/mypackage.package.json'),
requirejs: requirejsOptions,
jshint: jsHintOptions
});
// load plugin that enabled requirejs
grunt.loadNpmTasks('grunt-contrib-requirejs');
// load code quality tool
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('default', ['requirejs', 'jshint']); // <-- make sure your run jshint AFTER require
};
、インストール、ロード、およびgrunt-contrib-jshintを設定します。特定のファイルまたはファイルパスパターンを無視するオプションがignores
です。
jshint: {
options: {
// options here to override JSHint defaults
boss : true, // Suppress warnings about assignments where comparisons are expected
browser : true, // Define globals exposed by modern browsers (`document`, `navigator`)
curly : false, // Require curly braces around blocks
devel : false, // Define `console`, `alert`, etc. (poor-man's debugging)
eqeqeq : false, // Prohibit the use of `==` and `!=` in favor of `===` and `!==`
"-W041" : false, // Prohibit use of `== ''` comparisons
eqnull : true, // Suppress warnings about `== null` comparisons
immed : true, // Prohibit the use of immediate function invocations w/o wrapping in parentheses
latedef : true, // Prohibit the use of a var before it's defined
laxbreak: true, // Suppress warnings about possibly unsafe line breaks
newcap : true, // Require you to capitalize names of constructor functions
noarg : true, // Prohibit the use of `arguments.caller` and `arguments.callee`
shadow : true, // Suppress warnings about var shadowing (declaring a var that's declared somewhere in outer scope)
sub : true, // Suppress warnings about using `[]` notation, e.g. `person['name']` vs. `person.name`
trailing: true, // Trailing whitespace = error
undef : false, // Prohibit the use of explicitly undeclared variables
unused : false, // Warn when you define and never use your variables
white : false, // Check JS against Douglas Crawford's coding style
jquery : true, // Define globals exposed by jQuery
// Define global functions/libraries/etc.
globals : {
amplify : true
},
ignores: [
'src/app/templates/template.js',
'src/scripts/plugins/text.min.js'
]
},
gruntfile: {
src: 'Gruntfile.js'
},
app: {
src: 'src/app/**/*.js'
},
scripts: {
src: 'src/scripts/**/*.js'
}
}
- 1. Youtube Iframe API with RequireJS
- 2. キュービズムd3 dependency with requirejs
- 3. Typescript lazy load ember modules with requirejs
- 4. Loading:long、ByteBufferとProtoBuff with requirejs
- 5. RequireJSテキストプラグインの使用
- 6. 非RequireJSサイトのRequireJSモジュールの使用方法
- 7. requirejsを使用した統合ファブリック
- 8. ノックアウトとRequireJSを使用したカスタムバインディングハンドラ
- 9. ブックマークレットでRequireJSを使用する
- 10. import requirejs webpackを使用したamdモジュール
- 11. カスタムJSプラグインでRequireJsを使用する
- 12. RequireJSでVueJSを使用するには?
- 13. Requirejsシム構成でDEPSの使用
- 14. 複数のバージョンのRequireJSの使用
- 15. Assetic for requireJsの使用方法
- 16. RequireJSを使用しないAngular Dragulaの使用
- 17. 使用の違い@RequestMapping with with with method
- 18. Node.js require()とRequireJS? RequireJSと
- 19. Requirejs
- 20. 縮小したファイルでRequireJSとReact-domを使用する
- 21. requireJSまたはsystemJSを使用しないでtypescriptインポート/エクスポートを使用する
- 22. Requirejsを使用するタイミングとバンドルされたjavascriptを使用するタイミング
- 23. Requirejsを使用してWeb Workersをモジュールビルドに使用する方法は?
- 24. RequireJS - CDNを使用してスクリプト以外のファイルをロード
- 25. requirejsを使用してjquery.inputmaskを接続する方法
- 26. RequireJSを使用してCartoDbをロードするには?
- 27. ロケールファイルを動的にロードするRequirejsを使用して
- 28. Googleクローズコンパイラはrequirejsを使用してファイルを連結します
- 29. requirejsを使用してAngularJSルーティングとオンデマンドでコントローラをロードする
- 30. RequireJSを使用してJavaScriptでAMDを実装する
https://github.com/jshint/jshint#ignoring-files-and-directoriesような何か:
は、ここに私の仕事ですか? –