49

Modularize all the things

Embed Size (px)

DESCRIPTION

Publishing and reusing Javascript modules doesn't need to be hard. This talk shows some tips on how to use Package managers, use a module definition to share your work and finally how to publish it; so the world (including yourself) can reuse it later! Presented at JS Montreal in 12 august 2014

Citation preview

Page 1: Modularize all the things

MODULARIZE

ALL THE THINGS

Page 2: Modularize all the things

Building the case forModularization

Page 3: Modularize all the things

Real world examples:Monolithic applications

Page 4: Modularize all the things

The 2013 website

Page 5: Modularize all the things

The 2013 website

sticky header

parallaxcontact form

carousel

Page 6: Modularize all the things

The elephantin the room

Page 7: Modularize all the things

Reinventing the wheel

Page 8: Modularize all the things

Reinventing the wheelNot invented here syndrome

Page 9: Modularize all the things

Reinventing the wheelNot invented here syndrome

Learning curve

Page 10: Modularize all the things

You could haveit so much better

Page 11: Modularize all the things

Modularizing

Page 12: Modularize all the things

Identifyingreusableblocks

Page 13: Modularize all the things

What if reusing an elementcould be as simple as:

Page 14: Modularize all the things

What if reusing an elementcould be as simple as:

Page 15: Modularize all the things

Leaving thecomfort zone

Page 16: Modularize all the things

Time for a new

workflow

Page 17: Modularize all the things

PackageManagers

Page 18: Modularize all the things

npm:

default Node.js package managercomes with new Node.js installations

Page 19: Modularize all the things

most popular front-end package manager

must be installed using npm

Page 20: Modularize all the things

Differences between npm and Bower

Page 21: Modularize all the things

package.json bower.json

Page 22: Modularize all the things

Moduledefinition

Page 23: Modularize all the things

window.namespace

Page 24: Modularize all the things

window.namespace

Page 25: Modularize all the things

CommonJS

Page 26: Modularize all the things
Page 27: Modularize all the things

AMD

Page 28: Modularize all the things
Page 29: Modularize all the things

UMD

Page 30: Modularize all the things

UMD

Page 31: Modularize all the things

Frameworks

Page 32: Modularize all the things

AngularJS

Page 33: Modularize all the things

Angular has its own module definitions.Directives and Services are great!

Page 34: Modularize all the things

New technologies

Page 35: Modularize all the things

Web components

Page 36: Modularize all the things

Automating

Tasks

Page 37: Modularize all the things

Yeoman

Page 38: Modularize all the things

Yeoman is not only great for starting big projects.

Run a generator and get your modulestructure ready in a matter of seconds!

generator-nodegenerator-amdgenerator-angular

Page 39: Modularize all the things

Grunt

Page 40: Modularize all the things

Your Yeoman generator will certainly bring youa Gruntfile with many useful Grunt tasks by default.

Improve it with tasks to speed up module releases:

grunt-bumpgrunt-sg-release

Page 41: Modularize all the things

Publishing

Page 42: Modularize all the things

It doesn’t HAVE to be open-source. Both npm and Bowersupports many endpoints such as Git, SVN, zip, local folder, etc.

npm publish / bower register

Once our package is published we can just install and use it.

Page 43: Modularize all the things

Just as we wanted:

Page 44: Modularize all the things

Reusingthird-partymodules

Page 45: Modularize all the things

Cedric Dugas

“Can I code it myself easily?Do I have time?What browsers is this supporting?Number of open issues?What’s the code size?Do I trust this guy (or team)?”

Page 46: Modularize all the things

Share yourmodules!

Page 47: Modularize all the things

Merci!

@ruyadorno

http://ruyadorno.com

Page 48: Modularize all the things

- Paint all the memes by Sam Spratt: http://samspratt.com/- Monolith III by Tim Jarvis: http://www.magnasoma.co.uk/#/monolith-3- Elephant in the room photo: “Barely Legal” exhibition, September 15, 2006. (REUTERS/Fred Prouser)- Lego Color Bricks by Alan Chia: http://commons.wikimedia.org/wiki/File:Lego_Color_Bricks.jpg- Franz Ferdinand - You Could Have It So Much Better album cover- Go Gopher packages photo by Nathan Youngman: http://nathany.com/go-packages/- - Pattern tiles by Toni F: https://www.flickr.com/photos/st-lite/2660966951- Pile of Kittens by Peter Hasselbom: https://www.flickr.com/photos/peter_hasselbom/3072326220- Kitten k3 by Kubilay Ozvardar: https://www.flickr.com/photos/mrkubi/1222735107

Image Credits

Page 49: Modularize all the things

- Package management system: http://en.wikipedia.org/wiki/Package_management_system- Not Invented here: http://en.wikipedia.org/wiki/Not_invented_here- NPM Publish: https://www.npmjs.org/doc/cli/npm-publish.html- Bower API: http://bower.io/docs/api/- CommonJS: http://www.commonjs.org/- Browserify: http://browserify.org/- Nod- Node.js modules Doc: http://nodejs.org/api/modules.html- AMD: https://github.com/amdjs/amdjs-api- RequireJS: http://requirejs.org/- UMD: https://github.com/umdjs/umd- Bower.json spec: https://github.com/bower/bower.json-spec- npm package.json spec: https://www.npmjs.org/doc/files/package.json.html- AngularJS: https://angularjs.org/-- Web components: http://webcomponents.org/- Mout and modularity: http://blog.millermedeiros.com/mout-and-modularity/- Substack opinions on modules: http://substack.net/how_I_write_modules- Death to monolithic libraries by Cedric Dugas: http://www.position-absolute.com/articles/death-to-mono-lithic-libraries/

List of Javascript Package managers:

- npm: https://www.npmjs.org/- Bower: http://bower.io/- Volo: http://volojs.org/- Jam: http://jamjs.org/- Component: https://github.com/component/component

References