Gruntfile with grunt-contrib-watch, browser and hbsfy (handles) - conversion automation

I am new to most of these tools (grunt, draw, steer). I configure gruntfile.js to oversee the saving of several .js files and then automatically run them by default. Here is my current gruntfile.js :

 module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('node_modules/grunt/package.json'), watch: { js: { files: ['tvguide.js', 'responsive-tables.js'], tasks: ['browserify'] } }, browserify: { js: { src: ['responsive-tables.js','tvguide.js'], dest: 'bundle.js' } } }); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-handlebars'); grunt.loadNpmTasks('grunt-browserify'); grunt.registerTask('default', ['watch', 'browserify']); }; 

This works fine - although perhaps files and src are redundant. However, I got to the point where in my application, where I want to use steering wheels for templates, and many Google searches for a browser with handles led me to this npm hbsfy package. The instructions say that I would just run browserify -t hbsfy myscriptusingatemplate.js > bundle.js I would like this command to run automatically when I save certain .js files, but I'm not sure how to use both -o and -t in the same or different files.

I made several attempts using the options object, but nothing came of it. Any help / suggestions would be appreciated.

+5
source share
1 answer

If you want to use hbsfy from Grunt, use the following configuration:

 browserify: { js: { src: ['responsive-tables.js','tvguide.js','tmpl/**/*.handlebars'], dest: 'bundle.js' }, options: { transform: ['hbsfy'] } } 

Thus, you do not need to use grunt-contrib-handlebars at all.

In addition, I would suggest not using grunt-contrib-watch, but instead set the 'watch' option for the browser to true.

+6
source

Source: https://habr.com/ru/post/1201115/


All Articles