Published using Google Docs
Report abuse
Learn more
Grunt workflow POC
Updated automatically every 5 minutes
Grunt workflow POC
Create Project on GitHub
https://github.com/eshacker/grunt-and-minify-poc
Clone and use node
git clone git@github.com:eshacker/grunt-and-minify-poc.git && nvm use node
it clones the repo first.
it uses nvm to load node.
nvm is node version manager.
You probably would require to use https-url version instead of git-url for cloning.
cd into the directory.
npm init
mkdir src && cd src && mkdir css && mkdir js && touch index.html && cd ..
git add . && git commit -m "Structure of the example application." && git log -n1
You should see "Structure of the example application." as the last line of the output due to git log -n1
Fill up src/index.html, src/js/index.js, src/css/index.less
use any data.
get the app working.
Install grunt via node package manager
Read
http://gruntjs.com/getting-started
npm install -g grunt-cli
verify as follow
grunt --version should print grunt-cli v0.1.13 where v0.1.13 is variable and might be different for you.
install grunt plugin for uglifying JS.
https://github.com/gruntjs/grunt-contrib-uglify
install with
npm install grunt-contrib-uglify --save-dev
Check status by running
git status
You should see a change in package.json file and a directory node_modules created in the root of the repo.
Create a .gitignore file in the root of the directory and add
on a line
node_modules/
Now check git status again, you shouldn’t see node_modules.
you though will see a .gitignore file.
Create a Gruntfile.js
Get the basic configuration from
http://gruntjs.com/getting-started
update the structure using your head.
add this to Gruntfile.js
grunt.loadNpmTasks('grunt-contrib-uglify');
git add . && git commit -m “working js uglifier”
You probably want to
npm install grunt --save-dev
Check for output using
grunt
You should see a build/ or dist/ directory in root of repo if everything is going right.
Otherwise just follow the error.
Convert your CSS files to LESS files
Install grunt contrib less
https://github.com/gruntjs/grunt-contrib-less
npm install grunt-contrib-less --save-dev
add this to Gruntfile.js
grunt.loadNpmTasks('grunt-contrib-less');
Make changes as you wish.
Use compress option.
save changes in git repo.
Minify and copy html pages.
Install
npm install grunt-contrib-htmlmin --save-dev
Update Gruntfile.js
grunt.loadNpmTasks('grunt-contrib-htmlmin');
Of course you need to add htmlmin and less to the default task list and command grunt.
This POC/sample is complete. Time Taken: 2 hours 40 minutes.