Package Exports
- gulp-js-import-file
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gulp-js-import-file) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Forked version of https://github.com/nambo/gulp-js-import, adds more options.
INSTALL
npm install gulp-js-import --save-devUSAGE
First, install gulp-js-import as a devDependency:
Then add it to the gulpfile.js:
var gulp = require('gulp');
var jsImport = require('gulp-js-import');
gulp.task('import', function() {
return gulp.src('index.js')
.pipe(jsImport({
hideConsole: true,
importStack: true
}))
.pipe(gulp.dest('dist'));
});Final, run import task where you need, eg: gulp import
DEMO
you can get all code here
File Tree
this is the file tree:
demo
|
-- widget
| |
| -- widget.js
| |
| -- config.js
|
-- index.js
|
-- gulpfile.js
|
-- package.jsonBrief Intorduce
index.js:
// index.js
@import './widget/widget.js'
output(config);
// index.js endin index.js, you can use @import 'xxx.js' when you want import a js file
Options
- hideConsole - hides console
- importStack - import file only once
- es6import - you don't have to use @ as prefix
Run
Enter the demo directory in command
cd demoInstall gulp gulp-js-import
gulp installCompile files
gulp importYou could see a js file dist/index.js like this:
// index.js
// widget.js
// config.js
var config = 'this is config value';
// config.js end
function output(str) {
console.log(str);
}
// widget.js end
output(config);
// index.js end