7. PROBLEMS
1. I am not a hardcore JS Dev
2. How to make a browser library?
3. How to maintain state?
4. How to update the UI?
5. How to not go crazy while doing it?
8.
9. THIS TALK
1. Learn some JS!
2. Bundling
3. State Management Libraries
4. UI Management Libraries
5. Occasional Cat Pictures
12. BROWSERIFY
Browserify lets you require('modules') in
the browser by bundling up all of your
dependencies.
Browserify.org
browserify main.js -o bundle.js
Older
JS Only
No ES6 import/export
Not the smallest result
13. WEBPACK
A bundler for javascript and friends.
webpack.github.io
webpack input.js output.js
Newer
Handles many assets
No ES6 import/export
Not always smallest result
Not the simplest
14. ROLLUP
The next-generation JavaScript module
bundler
rollupjs.org
rollup input.js --output output.js
Newer
JS Only
No ES6 import/export
Tree shaking
Simple to use
15. ROLLUP
The next-generation JavaScript module
bundler
Write ES6 (aka ES2015)
Bundle into single file
Smaller than Browserify and Webpack
Export to AMD, CommonJS, ES2015, Globals, UMD
Tree shaking!
16. ES6
import fs from 'fs';
class AwesomeSauce {
constructor() {
// some code
}
makeIt() {
// some code
}
}
export default AwesomeSauce;
18. ES6
class AwesomeSauce {
// 100 lines of code
}
class EnterpriseSauce {
// 2000 lines of code
}
export EnterpriseSauce;
export default AwesomeSauce;
19. ES6
//import 2000 lines of code!
import { EnterpriseSauce } from 'awesome-sauce';
let sauce = new EnterpriseSauce();
sauce.makeItSecureButSlow();
20. ROLLUP TREE SHAKING
// main.js
import { cube } from './maths.js';
console.log( cube( 5 ) );
// maths.js
// unused function
export function square ( x ) {
return x * x;
}
// included function
export function cube ( x ) {
return x * x * x;
}
25. NPM
// js/index.js
import Dropin from './dropin/main.js';
let dropin = new Dropin();
export var setup = dropin.setup; // punch.setup() from earlier!
export var destroyAll = dropin.destroyAll;
export var instances = dropin.instances;
38. STATE MANAGEMENT
There are two hard things in computer science: cache
invalidation and naming things.
There are two hard things in computer science: cache
invalidation and naming things and state management
There are three hard things in computer science: cache
invalidation and naming things and state management
There are two hard things in computer science: cache
invalidation, naming things and state management
39.
40.
41. REDUX
Redux is a predictable state container for
JavaScript apps.
github.com/reactjs/redux
2kb
Including dependencies!
Before uglifying/compression!!
Riot compatible!!!
42. REDUX
npm install redux
// dropin.js
import './tags/punch-dropin.tag';
import riot from 'riot';
import { createStore } from 'redux';
import StoreMixin from 'riot-redux-mixin';
let state = ...
let store = createStore(state);
riot.mixin('redux', new StoreMixin(store));
riot.mount('#element', "punch-dropin");
51. CONCLUSIONS
Most of these are personal opinion
ES6 is lovely
RiotJS is easy and really small
Riot+Redux makes apps easy to comprehend
Rollup + NPM scripts beats Gulp and Grunt
52. NOTES
Some stuff isn't there yet
Rollup+Riot breaks sourcemaps
Riot Routes needs to be added
Hard to scientifically compare sizes