Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Consuming and Packaging of Web Components

Consuming and Packaging of Web Components

Presented on Meet.js Wrocław on April 28 2014

- solutions for package consuming
- tips about package publishing

Adam Stankiewicz

April 28, 2014
Tweet

More Decks by Adam Stankiewicz

Other Decks in Programming

Transcript

  1. bower • downloads components and dependencies • generic endpoints, many

    formats • uses registry for name -> endpoint mapping • leaves processing to other tools • huge community
  2. • like npm + browserify + grunt in one pack

    • does more than only downloading • no registry, github namespacing • can fetch components from npm registry
  3. Other options • jspm.io - Module Manager + Module Loader

    ◦ Can convert packages on-the-fly ◦ Supports AMD, CJS, ES6, globals • ender - CommonJS • volo - CommonJS • jam - AMD, dead
  4. npm install -g bower vim bower.json { "name": "myapp", "private":

    true, "dependencies": { "bootstrap-sass-official": "~3.1.1", "modernizr": "~2.6.2", "jquery": "~1.11.0" } }
  5. Basic bower usage $ bower install modernizr#2.6.3 bootstrap-sass-official#3.1.1+2 jquery#1.11.0 $

    ls ./bower_components bootstrap-sass-official jquery modernizr
  6. gulpfile.js - example var gulp = require('gulp'); var plug =

    require('gulp-load-plugins')(); gulp.task('scripts', function() { return gulp.src('app/scripts/**/*.coffee') .pipe(plug.coffee()) .pipe(plug.uglify()) .pipe(plug.concat('all.min.js')) .pipe(gulp.dest('build/js')); });
  7. Importing modules import "jquery" as $; $(function() { console.log("ok"); });

    var $ = require ("jquery") $(function() { console.log("ok"); }); ES6 style CJS style
  8. bower.json { "name": "unicorns", "description": "Provides unicorns", // "version": "0.1.0",

    "main": [ "dist/unicorns.js", "dist/unicorns.css" ], "moduleType": [ "amd", "globals" ], "license": "MIT", "ignore": [ "test", "bower_components" ] }
  9. bower.json - name, description { "name": "unicorns", "description": "Provides unicorns",

    // "version": "0.1.0", "main": [ "dist/unicorns.js", "dist/unicorns.css" ], "moduleType": [ "amd", "globals" ], "license": "MIT", "ignore": [ "test" ] }
  10. bower.json - version { "name": "unicorns", "description": "Provides unicorns", //

    "version": "0.1.0", "main": [ "dist/unicorns.js", "dist/unicorns.css" ], "moduleType": [ "amd", "globals" ], "license": "MIT", "ignore": [ "test" ] } • No need to use it • Use git tags instead • Use semver
  11. Semver (http://semver.org/) Good: • v0.1.0 • 0.1.0 • 0.1.0-rc1 •

    0.1.0-rc2.alpha Bad: • 0.1 • 0.1.0.rc.1 • 0.1.x • no tags at all
  12. bower.json - main { "name": "unicorns", "description": "Provides unicorns", //

    "version": "0.1.0", "main": [ "dist/unicorns.js", "dist/unicorns.css" ], "moduleType": [ "amd", "globals" ], "license": "MIT", "ignore": [ "test" ] } • Files should be present in repository • Also css entrypoint • No versioning like: dist/unicorns-0.1.0.js
  13. bower.json - moduleType { "name": "unicorns", "description": "Provides unicorns", //

    "version": "0.1.0", "main": [ "dist/unicorns.js", "dist/unicorns.css" ], "moduleType": [ "amd", "globals" ], "license": "MIT", "ignore": [ "test" ] } • Very important for processing tools • Supported types: amd, node, es6, globals, yui • You don’t need to support all of them
  14. Exporting modules 1. Use one of wrappers from umdjs/umd (function

    (root, factory) { if (typeof define === 'function' && define.amd) { define(['b'], factory); } else { root.unicorns = factory(root.b); } }(this, function (b) { return { run: function() { console.log('run!'); } }; }));
  15. Exporting modules 2. Write new components in ES6! Use gulp!

    exports unicorns var unicorns = { run: function() { console.log('run!'); } }
  16. Pro-tip: • Use separate repo for builds ◦ highslide-software/highcharts.com -

    60 MB ◦ highslide-software/highcharts-release - 300 KB