Pimp your imports!
Last updated 4 years ago by ngryman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install gulp-pimp 
SYNC missed versions from official npm registry.

gulp-pimp npm travis codecov

Pimp your imports!

pimp discovers your modules/components/whatever and automatically imports them in the file you want. You can then process it with the tool of your choice. It supports commonjs, sass, less, css by default. You can customize everything, of course.

That's not all, pimp is also a reducer, so you can use it for other purposes than simply importing stuff. As it's compatible with all plugins consuming gulp-data, you can use it with template engines for example.


npm install --save-dev gulp-pimp



gulp.src('app/components/*.js', { read: false })

app.js will contain:

var a = require('app/components/a.js');
var b = require('app/components/b.js');


return gulp.src('app/components/_*.scss', { read: false })

app.scss will contain:

@import 'app/components/_a.scss';
@import 'app/components/_b.scss';


return gulp.src('app/components/*.html', { read: false })
  .pipe(pimp('index.html', (output, file) => output + `{% include '${path}' %}` ))

index.html will contain:

{% include 'app/components/a.html' %}
{% include 'app/components/b.html' %}


pimp(manifest, [options])

manifest {string}

Name of the manifest file. If it already exists, imports are appended to the end of the file. If not the file is created.

options {object|function}

Set of options. If a function is passed, this is equivalent to the reducer option.

rules {object}

A set of rules to apply to input files. A rule is a key-value pair. The key is a glob to match, and the value is a template string that will be used to output the import statement.

The template string accepts several variables that will vary for each file being processed:

  • ${name}: name of the file, without the extension
  • ${path}: absolute path of the file


pimp('app.js', {
  rules: {
    'components/*/*.js': "import ${name} from '${path}'"
reducer {function}

The reducer gives you full control over statement substitution. It is called for each file. The function has 2 arguments:

  • output: which is the final output of all statements, or the data attribute if data is specified
  • file
    • name: name of the file, without the extension
    • ext: extension of the file
    • basename: name of the file, with the extension
    • path: absolute path of the file
    • contents: contents of the file as a string

As it's a reducer, make sure to always return output.


pimp('index.html', (output, file) => output + `<script src="${path}"></script>`);
intro {function}

Executed just before the reducer, it gives you the ability to setup and prepend something to output.

outro {function}

Executed just after the reducer, it gives you the ability to cleanup and append something to output.

data {boolean|string}

Alters pimp behavior by adding a data attribute to the manifest file, without modifying its content. This is mainly designed to be used with other plugins that consume gulp-data. If data is a string, collected files will be set in the given namespace (i.e. data.components).

data makes pimp switch of reducer. If you specify a custom reducer, it will take an object as first argument, instead of a string. intro and outro will have no effect.

Note that you should remove { read: false } when using this as you might actually need contents of your collected files.


But default, pimp comes with default rules:

  '*.{scss,less,css}': "@import '${path}';",
  '*.{js,jsx}': "var ${name} = require('${path}');"

If you want to modify those default, you can alter the pimp.RULES object.

Moar examples


pimp('app.js', {
  rules: {
    '*.js': 'import ${name} from ${path};'


const components = []

pimp('app.js', {
  intro: () => 'define([',
  reducer: (output, file) => { components.push(; return output + },
  outro: () => `], function(${components.join(', '}) {\n});\n`


This is an idea of what can be done using data.

Here is an index.html which will be processed by gulp-template:

  <%= components.header %>
    <%= components.content %>
    <%= components.aside %>
  <%= components.footer %>

pimp collects components and passes then to gulp-template:

  .pipe(pimp('index.html', { data: 'components' }))


MIT © Nicolas Gryman

Current Tags

  • 0.1.1                                ...           latest (4 years ago)

4 Versions

  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (4)
Dev Dependencies (9)
Dependents (1)

Copyright 2014 - 2016 © |