gulp-flatten-requires
v1.0.0
Published
Flattens relative require('./path/<module>') calls to require('./<module>')
Downloads
122
Maintainers
Readme
gulp-flatten-requires
Rewrites relative require()
calls to use flat paths in the same directory.
Whatever quote type was used in the original require()
call will be preserved.
| Before | After |
| ------------------------- | ---------------- |
| require('./path/to/a')
| require('./a')
|
| require('../path/to/b')
| require('./b')
|
| require("./c")
| require("./c")
|
Install
npm install --save-dev gulp-flatten-requires
Usage
This plugin is intended to be used in conjunction with gulp-flatten for a quick-and-dirty means of creating a flat directory of a library's modules to be published to npm for cleaner requiring of the library's constituent parts.
var gulp = require('gulp')
var flatten = require('gulp-flatten')
var flattenRequires = require('gulp-flatten-requires')
gulp.task('copy-npm', function() {
return gulp.src('./build/modules/**/*.js')
.pipe(flatten())
.pipe(flattenRequires())
.pipe(gulp.dest('./npm'))
})
Note: This assumes that every module in your project is uniquely named.