• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create static asset (js, css) bundles from a config file: a common interface to combining, minifying, revisioning and more

gulp-bundle-assets NPM version Build Status Coverage Status

Create static asset bundles from a config file: a common interface to combining, minifying, revisioning and more. Stack agnostic. Production ready.

By default uses the following gulp modules under the covers when creating bundles:

  1. gulp-concat
  2. gulp-sourcemaps
  3. gulp-uglify
  4. gulp-clean-css
  5. gulp-rev
  6. gulp-order

This project's stream architecture also allows you to plugin any gulp transform you wish.

Install

$ npm install gulp-bundle-assets --save-dev

Basic Usage

Create the following files:

// gulpfile.js
var gulp = require('gulp'),
  bundle = require('gulp-bundle-assets');

gulp.task('bundle', function() {
  return gulp.src('./bundle.config.js')
    .pipe(bundle())
    .pipe(gulp.dest('./public'));
});
// bundle.config.js
module.exports = {
  bundle: {
    main: {
      scripts: [
        './content/js/foo.js',
        './content/js/baz.js'
      ],
      styles: './content/**/*.css'
    },
    vendor: {
      scripts: './bower_components/angular/angular.js'
    }
  },
  copy: './content/**/*.{png,svg}'
};

Then, calling

$ gulp bundle

Will result in the following folder structure:

-- public
   |-- content
   |   |-- fonts
   |   |-- images
   `main-8e6d79da08.css
   `main-5f17cd21a6.js
   `vendor-d66b96f539.js

Advanced Usage

See the examples folder for many other config options. The full example shows most all available options.

Also check out our api docs.

Integrating bundles into your app

You can programmatically render your bundles into your view via your favorite templating engine and the resulting bundle.result.json file. To generate the bundle.result.json, add a call to bundle.results:

// gulpfile.js
var gulp = require('gulp'),
  bundle = require('gulp-bundle-assets');

gulp.task('bundle', function() {
  return gulp.src('./bundle.config.js')
    .pipe(bundle())
    .pipe(bundle.results('./')) // arg is destination of bundle.result.json
    .pipe(gulp.dest('./public'));
});

Which results in a bundle.result.json file similar to:

{
  "main": {
    "styles": "<link href='main-8e6d79da08.css' media='screen' rel='stylesheet' type='text/css'/>",
    "scripts": "<script src='main-5f17cd21a6.js' type='text/javascript'></script>"
  },
  "vendor": {
    "scripts": "<script src='vendor-d66b96f539.js' type='text/javascript'></script>",
    "styles": "<link href='vendor-23d5c9c6d1.css' media='screen' rel='stylesheet' type='text/css'/>"
  }
}

The order of the bundles will be the same as the order in which they were specified in the config.

See here for a full example using hogan

Other Features

  1. watch src files and only build specific bundles
    • Greatly speeds up development
    • e.g. split out vendor and custom js files into different bundles so the custom bundle continues to build quickly on src change
  2. different bundles for different environments
    • e.g. NODE_ENV=production gulp bundle could produce a set of bundles with minified src while just gulp bundle would have unminified src
  3. custom gulp transforms
    • e.g. use gulp-less, gulp-sass, gulp-coffee, etc to further transform your files
  4. consume pre-minified src files
    • e.g. use jquery.min.js in production and jquery.js in dev
  5. custom result types
    • e.g. create a bundle.result.json for html, jsx or any custom results you can think of
  6. works alongside 3rd party transformers
  7. guarantee bundle content order
  8. modify built-in behavior with custom gulp plugin options
  9. and much more!

Why?

There are a number of ways to bundle static assets for use in your webapp. Take for example: lumbar, brunch, webpack, browserify, optimizer, cartero, assetify, assets-packager, or simply a mashup of custom grunt or gulp plugins. All of these approaches are good in their own way but none of them did everything we needed:

  • handle all file types: js, css, less, sass, coffeescript, images, fonts, etc...
  • handle a variety of js managers: amd, requirejs, etc...
  • support common transforms: compression, minification, revisioning
  • support custom transforms, e.g. browserify
  • logic must be common across webapps. That is, no copy/pasting of tasks. This disqualified straight gulp or grunt.
  • work with existing community plugins, namely gulp tasks
  • work with src from multiple locations, e.g. bower_components, node_modules, etc
  • fast!

gulp-bundle-assets accomplishes all these goals and more. A main guiding principle behind this project is to provide all necessary bundling functionality while still being as flexible and customizable as possible.

Changelog

  • 2017/04/15 - v2.28.0 - add options to output src files in result #90 (@PlasmaPower)
  • 2016/05/23 - v2.27.0 - add consistent result.json ordering #71 (@PlasmaPower)
  • 2016/05/06 - v2.26.0 - update many deps including: gulp-less 3.1.0, gulp-coffee 2.3.2 and gulp-if 2.0.1
  • 2016/05/06 - v2.25.0 - update to use gulp-clean-css 2.0.7 instead of deprecated gulp-minify-css module
  • 2016/03/17 - v2.24.0 - update to gulp-less 3.0.5 and gulp-uglify 1.5.3
  • 2015/09/16 - v2.23.0 - add plugin option to modify built-in sourcemaps #65 (@narthollis)
  • 2015/07/17 - v2.22.0 - add config option for consistent file content ordering #25
  • 2015/06/11 - v2.21.0 - update all deps, including: gulp-rev 4.0.0, gulp-less 3.0.3, gulp-sourcemaps 1.5.2
  • 2015/05/07 - v2.20.0 - add pluginOptions config option #50
  • 2015/05/07 - v2.19.2 - update to gulp-minify-css 1.1.1 (@ZaleskiR)
  • 2015/04/24 - v2.19.1 - fix result.json url separator on windows #52 (@gregorymaertens)
  • 2015/03/01 - v2.19.0 - fix error handling for bundle.watch #47
  • 2015/02/08 - v2.18.0 - add flag to disabled sourcemaps #45 (@21brains-zh)
  • 2015/02/04 - v2.17.5 - update examples
  • 2015/02/04 - v2.17.4 - add logging for errors from custom transforms #41
  • 2015/02/03 - v2.17.3 - update examples
  • 2015/02/03 - v2.17.2 - add logging of bundle config parse errors
  • 2014/12/05 - v2.17.1 - fix custom result file name during bundle.watch (@roberto)
  • 2014/12/05 - v2.17.0 - add custom result file name #36 (@roberto)
  • 2014/12/04 - v2.16.1 - fix tests
  • 2014/12/01 - v2.16.0 - update deps, including: gulp-rev 2.0.1, gulp-sourcemaps 1.2.8, gulp-uglify 1.0.1
  • 2014/10/21 - v2.15.2 - add support for both minCSS and minCss #34
  • 2014/10/10 - v2.15.1 - add example using 6to5 (aka babel)
  • 2014/09/29 - v2.15.0 - add bundle.watch for copy files #33
  • 2014/09/29 - v2.14.0 - add flag to disable logging #16
  • 2014/09/25 - v2.13.1 - fix when bundleAllEnvironments: true, srcMin is always true #32
  • 2014/09/23 - v2.13.0 - add to allow different watch vs bundle targets #30
  • 2014/09/23 - v2.12.1 - fix to only publish results during watch when opts defined
  • 2014/09/23 - v2.12.0 - add bundle.watch for bundles #26

License

MIT

More Repositories

1

intentionjs

A library for intentionally dealing with responsive design
CSS
1,116
star
2

react-dropdown-tree-select

Lightweight, accessible, customizable and fast Dropdown Tree Select component for React
JavaScript
464
star
3

hammer

Dow Jones Hammer : Protect the cloud with the power of the cloud(AWS)
Python
435
star
4

fiveby

make selenium tests easier to setup, write, and execute
JavaScript
134
star
5

react-cellblock

react-based grid for smarter components
JavaScript
126
star
6

svg-text

A JavaScript library for creating multiline SVG <text> elements. Works seamlessly alongside SVG manipulation libraries such as Snap.svg and D3.
JavaScript
68
star
7

tokendito

Generate temporary AWS credentials via Okta.
Python
68
star
8

graphql-dynamodb-connections

DynamoDB pagination to GraphQL Connection adapter.
JavaScript
61
star
9

react-picture-show

Slideshow Component
JavaScript
55
star
10

react-json-schema-proptypes

Define React propTypes with JSON schema, then introspect and fake props
JavaScript
53
star
11

distribucache

Datastore-independent automatically-repopulating cache.
JavaScript
53
star
12

react-inline-style

Reusable and adaptable components without external css dependency.
JavaScript
50
star
13

reapsaw

Reapsaw is a continuous security devsecops tool, which helps in enabling security into CI/CD Pipeline. It supports coverage for multiple programming languages.
Python
42
star
14

slack-slash

Framework for handling slash commands in Slack
JavaScript
27
star
15

k8s-webhook

Companion code for a DJ Tech blog post https://medium.com/dowjones/how-did-that-sidecar-get-there-4dcd73f1a0a4
JavaScript
22
star
16

slack-slash-jira

Slack slash command handler for Jira.
JavaScript
19
star
17

Bigtable-dotnet

.NET client for Google Bigtable
C#
19
star
18

factiva-news-python

Python package to interact with Factiva news-related APIs. Services are described in the Dow Jones Developer Platform.
Python
19
star
19

graphql-rest-connections

This library helps with pagination in GraphQL, when backed by REST services.
JavaScript
16
star
20

respawn

AWS CloudFormation Template generator from Yaml specifications.
Python
16
star
21

DOMCapture

Capture DOM element as image 📷
JavaScript
11
star
22

react-tutorial

Dow Jones Technology: React Tutorial Session
JavaScript
11
star
23

envprops

Environment-specific property configuration library.
JavaScript
9
star
24

developer-platform

Dow Jones Developer Platform repository index.
Dart
9
star
25

dynamic-inset-renderer-node

Node.js dynamic inset renderer
JavaScript
8
star
26

CoolScrollSample

Java
8
star
27

dj-dna-streams-python

Python library for the DNA Streams API.
Python
7
star
28

factiva-sample-notebooks

Set of Jupyter Notebooks that shows how to use the Factiva packages published in PyPi.
Jupyter Notebook
6
star
29

dynamic-inset-renderer

A client-side javascript renderer for dynamic insets
JavaScript
6
star
30

di

Battle tested Node.js dependency injector
JavaScript
6
star
31

react-stuck

React component which loosely implements `position: sticky`
JavaScript
5
star
32

opensearch-blog

Building a distributed tracing pipeline with open telemetry collector, data prepper, Jaeger and OpenSearch
5
star
33

featureling

Feature handling package to assist in versioning an api or application
JavaScript
4
star
34

tabletop-clearcoat

Easy caching for tabletop-based google spreadsheets usage.
JavaScript
4
star
35

slush-fiveby

generator for https://github.com/dowjones/fiveby projects
JavaScript
4
star
36

RegionFlow

RegionFlow flows content into a region with fixed width and height.
JavaScript
3
star
37

distribucache-redis-store

A Redis datastore for Distribucache
JavaScript
3
star
38

dj-dna-streams-javascript

JavaScript library for the DNA Streams API.
JavaScript
3
star
39

lease

A memory (RAM) time-released lock for asynchronous resources.
JavaScript
3
star
40

namespaced-console-logger

Minimal namespaced stdout / stderr logger with a timestamp for the browser and Node.js.
JavaScript
3
star
41

glass-tabletop

A clearer view into data from Google Spreadsheets
JavaScript
3
star
42

react-draggable-list

A React component that enables a list of items to be reordered via drag and drop.
JavaScript
3
star
43

distribucache-memory-store

A memory (RAM) datastore for Distribucache
JavaScript
3
star
44

dynamic-inset-renderer-php

PHP renderer for dynamic insets
PHP
3
star
45

distribucache-stats

Distribucache statistics gathering library
JavaScript
2
star
46

lru-cache-pool

Pool of LRU caches
JavaScript
2
star
47

suppress-error

Wraps a function, suppresses node-style errors, and surfaces them in the value.
JavaScript
2
star
48

factiva-taxonomy-visualisation

Quick exercise to have an idea on how to analyse Dow Jones DNA (Factiva) hierarchies.
Jupyter Notebook
1
star
49

rover-runner

A VSCode extension to streamline local development with Apollo Studio and the Rover CLI
TypeScript
1
star
50

gulp-bundle-assets-example-aspnet-5

using gulp-bundle-assets for front-end concat, minify, uglify, etc
C#
1
star
51

passport-http-encrypted-token

HTTP Encrypted Token authentication strategy for Passport and Node.js
JavaScript
1
star
52

rpm-extract

Programmatically extract files from rpm packages
JavaScript
1
star
53

generator-slack-slash

Yeoman generator for slack-slash app and handler plugins.
JavaScript
1
star
54

distribucache-console-logger

Distribucahce stdout / stderr logger
JavaScript
1
star
55

factiva-core-python

Python package with root definitions and dictionaries, to support other functional packages.
Python
1
star