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

Frontend tools 4 frontend stuff

Frontend tools 4 frontend stuff

Talk about the changes in the frontend stack @ Uniplaces

Miguel Loureiro

December 15, 2014
Tweet

More Decks by Miguel Loureiro

Other Decks in Programming

Transcript

  1. Current stack • Bower ( SpBowerBundle ) • Sass (

    CompassElephphantBundle ) • Requirejs ( HearsayRequireJsBundle ) • Assetic
  2. Steps for production assets • Minify, uglify and concat js

    • Compile sass, minify css and concat • Cache-bust • Copy all assets to a new dist folder from where they will be served
  3. Summary • NPM ( our composer for node ) •

    Bower ( our composer for web modules i.e. jquery ) • Compass ( like compass lol ) • Grunt ( like app/console in symfony )
  4. The common layer • web/assets/js/common.js • the first layer of

    our js • every page loads dependencies in this file first and the requested dependency comes after • avoids the timeouts we were having • we also use this as the requirejs config file where we tell where to find our js modules
  5. Shim Use shim option in require config to load dependencies

    that have no AMD support Then you can force it to load in correct order
  6. Optimizing require.js • Configuration used for r.js ( the optimizer

    ) • We can define modules and tell what we want to include in each module. • We can also exclude modules that are already being imported from others
  7. Gruntfile.js • init variables to use in the file •

    prefix variable for cache busting • copy task
  8. Gruntfile.js • requirejs task • using <%= appDir %> to

    build the string • this is copy pasted from the previous example of require.js config. It integrates that nicely in grunt.
  9. Registering tasks This is what enables us to run tasks

    with grunt <task>, grouping the tasks
  10. Improvements • Use If-modified-since • Improve cache-bust • Better way

    to integrate assets url replacement • gzip assets
  11. All you need to know npm install ( install node

    dependencies ) npm install <package> —save-dev ( install dependency and update package.json ) bower install <package> ( install web component dependency on assets/vendor ) grunt watch ( watch for sass updates and auto compile css ) grunt ( build assets for dev ) grunt prod ( build assets for prod ) grunt <command> —force ( don’t stop execution on errors ) grunt compass:dev ( only compile sass for dev ) grunt prepare ( only copy files from other repositories to web ) grunt requirejs ( only build js without uglify ) ./update-assets-prefix.sh <preffix> ( replaces all __GRUNTPREFFIX__)