Skip to content

How can I share my bundle configuration with other applications in different languages?

Alex Weissman edited this page Mar 24, 2016 · 2 revisions

Sometimes, you might want your bundle configuration to be easily parsed in other languages (such as PHP) or by other applications. Fortunately, the configuration for gulp-bundle-assets is a JSON object, an inter-operable format natively supported by most major programming languages.

To expose the JSON object in your bundle config file, you can simply omit the module.exports = and the ;, and even rename the file as a .json if you wish:

bundle.config.json

{
  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}'
}

You can load this file into a gulp stream exactly the same way you would the .js version:

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

gulp.task('bundle', function() {
  return gulp.src('./bundle.config.json')
    .pipe(bundle())
    .pipe(gulp.dest('./public'));
});

It then becomes easy to access your bundle configuration in other languages, such as PHP:

$bundle = json_decode(file_get_contents('./bundle.config.json', FILE_USE_INCLUDE_PATH),true);