/ Polymer

Remove bower_components from dist via gulp script

When you run gulp task, it generates and compresses all the files required for a webserver to run. The default gulp task does things like vulcanize which reduces the number of calls the browser has to make when loading your polymer app.

For the defaults in Polymer Starter Kit it's good practice to import all your top level custom elements in the elements file (if your custom elements have sub imports, you don't need to import the sub imports in the elements.html file). The vulcanize task starts from there and copies the contents of all the imported elements/dependencies into a single file elements.vulcanized.html

The index.html in the dist\ folder is then reconfigured to import elements.vulcanized.html (one call) as opposed to importing elements.html which may have many imports (each import results in further calls/loads) of elements which then has more imports, etc.

So with all the polymer and other elements (e.g. paper, neon, iron, etc.) placed into a single file, there's no need for the bower_components directory to exist. Plus, you always have the original bower_components directory in the root folder of Polymer Starter Kit. It seems redundant and takes up extra space (12 MB). I think this is part of a confusion from using dist\ as both an interim folder and the final destination for the deployable goods.

Currently, I created a gulp task to remove anything unused folders which (if you don't use any serviceworker) are the bower_components folder and the sw-toolbox folder.

Here's the task that I added to gulpfile.js:

//Remove bower_components and other unused folders
gulp.task('delunused', del.bind(null, ['dist/bower_components', 'dist/sw-toolbox']))

I then added delunused after the vulcanize task in the default.

// Build Production Files, the Default Task
gulp.task('default', ['clean'], function (cb) {
  runSequence(
    ['copy', 'styles'],
    'elements',
    ['jshint', 'images', 'fonts', 'html'],
    'vulcanize',
    'delunused',
    cb);
});