gulp-resolve-dependencies-advanced
v0.1.0
Published
Extra features for gulp-resolve-dependencies
Downloads
28
Maintainers
Readme
gulp-resolve-dependencies-advanced
This library aims to add some extra features to gulp-resolve-dependencies.
It all started when I needed the library to be able to:
- Resolve dependencies from external directories (i.e. node_modules)
- Resolve dependencies without an explicit extension (i.e.
import React from "react";
)
Usage
First, install gulp-resolve-dependencies-advanced
as a development dependency:
npm install --save-dev gulp-resolve-dependencies-advanced
Import gulp-resolve-dependencies
as usual and override the resolvePath
option to use advancedPathResolver
which implements an advanced strategy for resolving paths:
var resolveDependencies = require('gulp-resolve-dependencies');
var advancedResolveDependencies = require('gulp-resolve-dependencies-advanced');
var concat = require('gulp-concat');
gulp.task('resolve-dependencies', function(){
gulp.src(['./src/components/main.tsx'])
.pipe(resolveDependencies({
pattern: /import .* \"(.*)\";/g, // Accept import without explicit extension
resolvePath: advancedResolveDependencies.advancedPathResolver({
paths: {
"*": [path.resolve(__dirname, "node_modules")] // Resolve files in node_modules
},
extensions: [".tsx", ".jsx", ".ts", ""],
mainFiles: [
"index.jsx",
"index.tsx",
"index.js",
"index.ts"
]
}),
exclude: [
path.resolve(__dirname, "node_modules/**/*"),
path.resolve(__dirname, "src/**/utils.ts")
]
}))
.on('error', function(err) {
console.log(err.message);
})
.pipe(concat())
.pipe(gulp.dest('dest/assets/js/'));
});
Testing
$ git clone https://github.com/Nauja/gulp-resolve-dependencies-advanced.git
$ cd gulp-resolve-dependencies-advanced
$ npm install
$ npm test
License
Licensed under the MIT License.