Reputation: 10303
I would like to use grunt.js as a build tool for my web project. Can I use grunt.js to validate my HTML/CSS files? Do you have an example of such a grunt.js file?
Upvotes: 9
Views: 4481
Reputation: 4331
As of now there seem to be two popular HTML validation plugins:
grunt-html-validation
uses the W3C Markup Validation Service and grunt-html
uses a local copy of the java-based The Nu HTML Checker.
They both work well and have very similar options so it comes down to whether you want to wait for an external service call or wait for a local java app.
Upvotes: 2
Reputation: 5544
There is another plugin that seems to be updated more often and does not require java. grunt-html-validation. It has a number of options and has been working great for me. You can install and use it like this:
npm install grunt-html-validation --save-dev
Then put something like this in the initconfig of your Gruntfile.js
and this in appropriate places in your Gruntfile.js
grunt.loadNpmTasks('grunt-html-validation');
grunt.registerTask("default", ["validation"]);
There is also a number of useful options including the ability to relax errors based on a regular expression (could be useful for AngularJS for example) and the ability to save a report.
Upvotes: 7
Reputation: 7651
You can use the grunt plugin grunt-html. Beware, you will need Java on your computer to use it. It works well for me.
Upvotes: 4