-
Notifications
You must be signed in to change notification settings - Fork 4
Compiling JavaScript Packages Using Grunt
Franz Noel edited this page Dec 31, 2015
·
7 revisions
This documentation explains how to compile JavaScript codes using npm
and grunt
For Java experienced developers: Grunt compiles files, libraries, or packages using JavaScript configuration. In other words, it is similar to Ant, a software that helps compile Java codes before the main Java program runs.
- Create the folder running
mkdir project-name
- Run
npm init
and fill out the name, version, description, entry point, test command, git repository, keywords, author, and license
- Run
npm install -g grunt-cli
to install grunt command line. - Run
npm install grunt-contrib-jshint grunt-contrib-nodeunit grunt-contrib-uglify --save-dev
to install Grunt plugins in package.json
-
Run
vi Gruntfile.js
. Then, copy and paste the following codes:module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, build: { src: 'src/<%= pkg.name %>.js', dest: 'build/<%= pkg.name %>.min.js' } } }); // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); // Default task(s). grunt.registerTask('default', ['uglify']); };
-
Make sure to save in
vi
interface by typing:wq!
-
Run
grunt
command to minify (oruglify
) the source file, based on the configuration.
- Keep on configuring Gruntfile.js
- Keep on running
grunt
until you get the right results.