This article is part of a series of posts on RequireJs, AnguarJs, Grunt and Bower. Here are the parts so far:
- AngularJs, RequireJs, Grunt and Bower Part1 - Getting Started and concept with ASP.NET MVC
- AngularJs, RequireJs, Grunt and Bower Part2 - Grunt
- AngularJs, RequireJs, Grunt and Bower Part3 - generator-angular-requirejs-grunt-bower with ASP.NET MVC
- AngularJs, RequireJs, Grunt and Bower Part4 - How to extend your own code with ASP.NET MVC
- AngularJs, RequireJs, Grunt and Bower Part5 - generator-angular-requirejs-grunt-bower with Express.js //to be done
Grunt
Why use a task runner?
In one word: automation. The less work you have to do when performing repetitive tasks like minification, compilation, unit testing, linting, etc, the easier your job becomes. After you’ve configured it, a task runner can do most of that mundane work for you—and your team—with basically zero effort.
Why use Grunt?
The Grunt ecosystem is huge and it’s growing every day. With literally hundreds of plugins to choose from, you can use Grunt to automate just about anything with a minimum of effort. If someone hasn’t already built what you need, authoring and publishing your own Grunt plugin to npm is a breeze.
If you are familiar with Grunt. You could feel how powerful it is, how could it reduce your repetitive tasks and make your work more easier.
Grunt with our ASP.NET MVC Project
Concept
...
Public
└── js
| ├── controllers
| ├── css
| ├── directives
| ├── services
| ├── vendor
| ├── filters
| ├── views
| | └── ...
| ├── app.js
| └── config.js
└── release
├── views
| └── ...
├── app.js
└── config.js
In AngularJs, RequireJs, Grunt and Bower Part1 - Getting Started and concept with ASP.NET MVC ~ 竹部落 post. We talk about how to integrate AngularJs, RequireJs, Grunt and Bower with our ASP.NET MVC project and put all of code in Public/js
folder. Browser will load those files one by one by following RequireJs definition and dependencies we define in Public/js/config.js
.
Be a large AngularJs single page application, you might include a lots of file to the project. For example: in our ASP.NET MVC project. Implement the file structure i mentioned in last post. Browser will load more the 20 file. Web page loading speed will increase if browser load more files. During development, separation of concerns (SoC) will help us to break down the problem to smaller. So, we need a solution to help us to combine related file and decrease web page loding speed in release mode. That’s Rquirejs + Grunt.
RequireJs + Grunt
Our gold is improve page loading speed by reduce include file count in our project in final release/product. RequireJs has an optimization tool can help us to combine related file and minifies them and grunt-contrib-requirejs
and put RequireJs work with Grunt well.
REQUIREJS OPTIMIZER
Combines related scripts together into build layers and minifies them via UglifyJS (the default) or Closure Compiler (an option when using Java).
Optimizes CSS by inlining CSS files referenced by @import and removing comments.
Gruntfile.js
module.exports = function(grunt) {
'use strict';
require('load-grunt-tasks')(grunt);
// configurable paths
var mvcConfig = {
js: 'js',
release: 'release',
tmp: 'tmp'
};
grunt.initConfig({
mvc: mvcConfig,
clean: {...},
copy: {...},
requirejs: {...},
concat: {...},
uglify: {...},
htmlmin: {...},
jshint: {...},
cssmin: {...}
});
// task
grunt.registerTask('build', [
'clean:release',
'clean:tmp',
'copy:vendor',
'copy:module',
'requirejs',
'copy:basic',
'copy:css',
'cssmin',
'clean:tmp',
'htmlmin'
]);
grunt.registerTask('default', [
'jshint',
'build'
]);
};
We can define multiple grunt tasks in Gruntfile.js
. All you need to do is executing command grunt
. Grunt will execute all of tasks one by one. How, let we check before doing the grunt task.
- using
bower
package manager to handle what library we include and put all libraries invendor
. Ex: AngularJs, jQuery , moment ects. config.js
define the library dependencies and library path.- implement file structure as we mentioned before.
Our Grunt scenario is copy required file from public/js/...
to public/tmp/...
folder. Grunt task requirejs:complie
will combine scripts together and put it in public/release
folder.
grunt-contrib-requirejs
optimize RequireJS projects using r.js. Most of needed configuration is same as RequireJs required but file path. We need to modify file path to our temporary folder tmp
.
paths: {
...
'angular': '../<%= mvc.tmp %>/vendor/angular',
'jquery': '../<%= mvc.tmp %>/vendor/jquery.min',
...
One more thing. We need to replace file path in our release RequireJs config.js
from js
to release
. It will make sure relese RequireJs config.js
is reference to current source folder.
onBuildRead: function(moduleName, path, contents) {
if (moduleName === 'config') {
var x = (function(contents) {
var regex = /'(vendor|libs)[^']*'/gm;
var matches = contents.match(regex);
for (var i = 0; i < matches.length; i++) {
var match = matches[i];
var m = matches[i].split('/');
contents = contents.replace(match, '\'vendor/' + m[m.length - 1].toLowerCase());
}
return contents;
})(contents);
return x.replace(/\/public\/js/g, '/public/release');
}
return contents;
},
Visit to Github to check whole Gruntfile.js file.
build.txt
After you execute command grunt
. build.txt
will be created automatically. It is a requirejs:complie
log file and show you a list what libraries and user define scripts are combined together base on Gruntfile.js
requirejs
complie module setting.
// config.js
requirejs: {
compile: {
options: {
...
modules: [{
name: 'views/Home/index'
}],
...
}
}
},
// build.txt
views/Home/index.js
----------------
vendor/jquery.min.js
vendor/moment.min.js
vendor/angular.js
vendor/respond.js
controllers/controllers.js
filters/filters.js
directives/directives.js
vendor/angular-resource.js
services/services.js
vendor/angular-animate.js
vendor/angular-cookies.js
vendor/angular-route.js
vendor/angular-sanitize.js
vendor/angular-touch.js
vendor/bootstrap.min.js
vendor/ui-bootstrap.min.js
vendor/ui-bootstrap-tpls.min.js
app.js
vendor/domReady.js
controllers/home-controller.js
views/Home/index.js
Preview
Final step, we need to change solution configuration from Debug
to Release
in Visual Studio toolbar and rebuild the project. Open Chrome Developer tools and switch to Network panel. You will see browser load two files config.js
and index.js
Reference
Github Source Code
cage1016/AngularJsRequireJsGruntBower
After you clone source code from github repo, you can run following command:
git checkout -f step-0
is status project createdgit checkout -f step-1
is status Nuget install Require.js.git checkout -f step-2
is status project Add AngularJs, RequireJs, Grunt and Bower to Public folder.git checkout -f step-3
is status modify _Layout.chtml to render RequireJs. You will see the final result.
- Please cd to
AngularJsRequireJsGruntBower\AngularJsRequireJsGruntBower\Public
and executebower install
to restore those library project included.
- Please cd to
git checkout -f setp-4
is status ready to do grunt tasks.
- Please cd to
AngularJsRequireJsGruntBower\AngularJsRequireJsGruntBower\Public
and executenpm install
to restoregrunt
required libraries. - execute command
grunt
to do grunt tasks.
- Please cd to
Pretty post, I hope your site useful for many users who want to learn basics of programming to enhance their skill for getting good career in IT, thanks for taking time to discuss about fundamental programming niche.
ReplyDeleteWith Regards,
Angularjs training in chennai|Angularjs course in chennai
ReplyDeleteThe oracle database is capable of storing the data in two forms such as logically in the form of table spaces and physically like data files.
Oracle Training in Chennai | oracle dba training in chennai
Great work.Very informative post.
ReplyDeleteOnline AngularJS Training |AngularJS Training in Chennai | Angular2 Online Training
My rather long internet look up has at the end of the day been compensated with pleasant insight to talk about with my family and friends.
ReplyDeletebig-data-hadoop-training-institute-in-bangalore
this is great posti like the way you explain little things thanks for sharing
ReplyDeletetutuapp apk
instagram sign up
Great post! I really liked the reading experience. Keep us updated with more such posts.
ReplyDeleteExcel Training in Chennai
Excel Course in Chennai
Unix Training in Chennai
Unix Shell Scripting Training in Chennai
JavaScript Training in Chennai
JavaScript Course in Chennai
Excel Training in Velachery
Excel Training in Tambaram
ReplyDeleteI enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again.
site...
ReplyDeleteThanks for sharing the information. It is very useful for my future. keep sharing
site...
Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
ReplyDeletemobile service centre
Thanks for your post which gather more knowledge about the topic. I read your blog everything is helpful and effective.
ReplyDeletePython Training in Chennai
Python Course in Chennai
Python Training in Velachery
Python Training in Tambaram
Java Training in Chennai
Java Course in Chennai
Java Training in Anna Nagar
Java Training in Velachery
I wanted to thank you for this great blog! I really enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
ReplyDeleteDigital Marketing Training in Coimbatore
Digital Marketing Course in Coimbatore
Android course in coimbatore
CCNA Training in Coimbatore
cloud computing training in coimbatore
embedded training in coimbatore
ethical hacking course in coimbatore
German Language course in Coimbatore
Happy to read this blog very nice, in this technology world
ReplyDeleteAws training chennai | AWS course in chennai
manual testing course chennai | Manual testing class chennai
For Big Data And Hadoop Training in Bangalore Visit - Big Data And Hadoop Training In Bangalore
ReplyDeleteI believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
ReplyDeleteAws training chennai | AWS course in chennai
Rpa training in chennai | RPA training course chennai
sas training in chennai | sas training class in chennai
Hey Nice Blog!! Thanks For Sharing!!! Wonderful blog & good post. It is really very helpful to me, waiting for a more new post. Keep Blogging!Here is the best angular training online with free Bundle videos .
ReplyDeletecontact No :- 9885022027.
SVR Technologies
This comment has been removed by the author.
ReplyDeleteWonderful blog. It is really informative to all.keep update more information about this
ReplyDeleteTally Course in Chennai
Tally Course in Hyderabad
Tally training coimbatore
Tally Course in Coimbatore
Tally course in madurai
Tally Training in Chennai
Tally Institute in Chennai
Tally Training Institute in Chennai
Selenium Training in Bangalore
Ethical hacking course in bangalore
buy white widow weed online
ReplyDeletebuy purple haze weed online
buy og kush weed online
buy west coast cure carts
buy brass knuckles vape cartridges
buy muha meds carts online
Thanks for the informative article About Java. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
I like this one...more helpful information provided here.I am quite sure I will learn much new stuff right here! Good luck for the next!
ReplyDeleteOracle Training | Online Course | Certification in chennai | Oracle Training | Online Course | Certification in bangalore | Oracle Training | Online Course | Certification in hyderabad | Oracle Training | Online Course | Certification in pune | Oracle Training | Online Course | Certification in coimbatore
Interesting blog, it gives lots of information to me. Thanks for sharing such a nice blog.
ReplyDeletepython training in bangalore | python online training
aws online training in bangalore | aws online training
artificial intelligence training in bangalore | artificial intelligence online training
machine learning training in bangalore | machine learning online training
data science training in bangalore | data science online training
Interesting blog, it gives lots of information to me. Thanks for sharing such a nice blog.
ReplyDeletepython training in bangalore | python online training
aws online training in bangalore | aws online training
artificial intelligence training in bangalore | artificial intelligence online training
machine learning training in bangalore | machine learning online training
data science training in bangalore | data science online training
The oracle database is capable of storing the data in two forms such as logically in the form of table spaces and physically like data files.
ReplyDeletejava training in chennai
java training in omr
aws training in chennai
aws training in omr
python training in chennai
python training in omr
selenium training in chennai
selenium training in omr
I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!
ReplyDeletejava training in chennai
java training in tambaram
aws training in chennai
aws training in tambaram
python training in chennai
python training in tambaram
selenium training in chennai
selenium training in tambaram
First i got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks
ReplyDeletedata science training in chennai
data science training in porur
android training in chennai
android training in porur
devops training in chennai
devops training in porur
artificial intelligence training in chennai
artificial intelligence training in porur
I just recently discovered your blog and have now scrolled through the entire thing several times. I am very impressed and inspired by your skill and creativity, and your "style" is very much in line with mine. I hope you keep blogging and sharing your design idea
ReplyDeletejava training in chennai
java training in velachery
aws training in chennai
aws training in velachery
python training in chennai
python training in velachery
selenium training in chennai
selenium training in velachery
Really impressive post. I read it whole and going to share it with my social circules. I enjoyed your article
ReplyDeletejava training in chennai
java training in velachery
aws training in chennai
aws training in velachery
python training in chennai
python training in velachery
selenium training in chennai
selenium training in velachery
Very informative blog and useful article thank you for sharing with us,
ReplyDeleteby cloudi5 offers AWS Training in Chennai
Honestly speaking this blog is absolutely amazing in learning the subject that is building up the knowledge of every individual and enlarging to develop the skills which can be applied in to practical one. Finally, thanking the blogger to launch more further too.
ReplyDeleteData Science Course in Bhilai
BUY WEED ONLINE
ReplyDeleteBUY IBOGAINE ONLINE
BUY XANAX ONLINE
BUY DANK VAPE ONLINE
BUY LSD ONLINE
BUY COCAINE ONLINE
BUY IBOGAINE ONLINE
BUY MOONROCKS ONLINE
BUY DANK VAPE ONLINE
ReplyDeleteWay cool! Some very valid points! I appreciate you penning this article and also the rest of the site is really good.
Technology
I think this is an informative post and it is very useful and knowledgeable. therefore. I would like to thank you for the efforts you have made in writing this article.
ReplyDeleteDevOps Training in Chennai
DevOps Course in Chennai
ReplyDeletecancel automatic renewal of the avast subscription
Cognex offers AWS training in Chennai using classroom and AWS Online Training globally.
ReplyDeleteclick here
ReplyDeleteAmazing post.Thanks for sharing.........
Cyber Security Course in Pune
Cyber Security Course in Gurgaon
Cyber Security Course in Hyderabad
Cyber Security Course in Bangalore
This is a very nice one and gives in-depth information. I am really happy with the quality and presentation of the article. I’d really like to appreciate the efforts you get with writing this post. Thanks for sharing.
ReplyDeletePython classes in Ahmednagar
Python classes in Amravati
Python classes in Nashik
Mua vé tại đại lý vé máy bay Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ giá bao nhiêu
lịch bay từ mỹ về việt nam hôm nay
vé máy bay từ Toronto về việt nam
mua vé máy bay từ nhật về việt nam
vé máy bay vietjet từ hàn quốc về việt nam
Vé máy bay từ Đài Loan về VN
danh sách khách sạn cách ly tại tphcm
Cyber Security Course in Mumbai
ReplyDeleteCyber Security Course in Ahmedabad
Cyber Security Course in Kochi
Cyber Security Course in Trivandrum
Cyber Security Course in Kolkata
The Growing Imporance of Cyber Security Analytics
Wonderful blog. Thanks for sharing a useful information.........
ReplyDeleteGoogle Analytics Training In Chennai
Google Analytics Online Course
Mobilemall Bangladesh Really nice blog. thanks for sharing such a useful information.
ReplyDelete
ReplyDeleteThis post is so interactive and informative.keep update more information...
Tally Course in Tambaram
Tally course in Chennai
Such a good post .thanks for sharing
ReplyDeleteWeb Designing Course in Porur
Web Designing Course in chennai
Very Informative, good stuff. A good article is one that a person is aware of, to get something to learn from that article and your article is also one of them.We hope that you will share a similar article in the future and make us aware thank you.
ReplyDeleteRead more articles here:
The Masters Real Estate
Lahore Smart City
Capital Smart City map
Faisalabad Smart City
Park View City Islamabad
Park View City Lahore
Nova City Islamabad
360DigiTMG, the top-rated organisation among the most prestigious industries around the world, is an educational destination for those looking to pursue their dreams around the globe. The company is changing careers of many people through constant improvement, 360DigiTMG provides an outstanding learning experience and distinguishes itself from the pack. 360DigiTMG is a prominent global presence by offering world-class training. Its main office is in India and subsidiaries across Malaysia, USA, East Asia, Australia, Uk, Netherlands, and the Middle East.
ReplyDeleteNice Post. Thanx for Sharing.
ReplyDeleteCyber Security Course
Cyber Security Interview Questions
mmorpg oyunlar
ReplyDeleteinstagram takipçi satın al
Tiktok Jeton Hilesi
Tiktok jeton hilesi
antalya saç ekimi
referans kimliği nedir
İNSTAGRAM TAKİPÇİ SATIN AL
metin2 pvp serverlar
instagram takipçi satın al
SMM PANEL
ReplyDeleteSMM PANEL
https://isilanlariblog.com/
İNSTAGRAM TAKİPÇİ SATIN AL
hirdavatciburada.com
BEYAZESYATEKNİKSERVİSİ.COM.TR
SERVİS
Jeton Hilesi İndir
Great Blog. Agile Interview Questions and Answers
ReplyDeleteThis comment has been removed by the author.
ReplyDeletethanks for sharing valuable info..........
ReplyDeleteSSR Movies
Thanks for sharing important information about Angular requirejs , keep posting , also wanted to learn about Python then visit: Python Training in Pune
ReplyDeletepython programming classes in Pune