gulp-flatten-imports
v1.0.0
Published
Rewrites relative import calls to use flat paths in the same directory.
Downloads
2
Maintainers
Readme
gulp-flatten-imports
Rewrites relative import
calls to use flat paths in the same directory.
| Before | After |
| ------------------------- | ---------------- |
| import defaultExport, { export1 [ , [...] ] } from "./unflattened/path/to/file/module-name";
| import defaultExport, { export1 [ , [...] ] } from "./module-name";
|
| import defaultExport, * as name from "./unflattened/path/to/file/module-name";
| import defaultExport, * as name from "./module-name";
|
| import "./unflattened/path/to/file/module-name";
| import "./module-name";
|
| var promise = import("./unflattened/path/to/file/module-name");
| var promise = import("./module-name");
|
| var promise = import("./unflattened/path/to/file/module-name");
| var promise = import("./module-name");
|
| import "module-name";
| import "module-name";
|
Install
npm install --save-dev gulp-flatten-imports
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 flattenImports= require('gulp-flatten-imports')
gulp.task('flatten', function() { return gulp.src('./src/**/*.js') .pipe(flatten()) .pipe(flattenImports()) .pipe(gulp.dest('./build')) })
Note: This assumes that every module in your project is uniquely named.