Follow these steps to configure GruntJS:
Make sure you install your package.json or install a new one:
npm init
Install Grunt CLI as Global:
npm install -g grunt-cli
Install Grunt in your local project:
npm install grunt
Install any Grunt module that you may need during the build process. Just for the sake of this sample, I will add the Concat module to merge files together:
npm install grunt-contrib-concat
Now you need to configure Gruntfile.js , which will describe your build process. For this example, I simply merge the two JS files file1.js and file2.js in the js folder and generate app.js :
module.exports = function(grunt) { // Project configuration. grunt.initConfig({ concat: { "options": { "separator": ";" }, "build": { "src": ["js/file1.js", "js/file2.js"], "dest": "js/app.js" } } }); // Load required modules grunt.loadNpmTasks('grunt-contrib-concat'); // Task definitions grunt.registerTask('default', ['concat']); };
Now you will be ready to start the build process by running the following command:
grunt
Hope this gives you an idea of ββhow to work with the GruntJS build.
NOTE:
You can use grunt-init to create Gruntfile.js if you want to create based on the wizard instead of the raw coding for step 5.
To do this, follow these steps:
npm install -g grunt-init git clone https://github.com/gruntjs/grunt-init-gruntfile.git ~/.grunt-init/gruntfile grunt-init gruntfile
For Windows users: if you use cmd.exe, you need to change ~/.grunt-init/gruntfile to %USERPROFILE%\.grunt-init\ . PowerShell correctly recognizes ~ .
Qorbani Mar 29 '13 at 22:41 2013-03-29 22:41
source share