Inline any ES6 import by fetching its resource down to the importing file.
from
import './func1.js';
var func2 = function() {
func1();
}
export default func2;
to
var func1 = function() {
// ...
}
var func2 = function() {
func1();
}
export default func2;
On your node.js root project folder:
npm install --save-dev gulp-inline-import
Or
yarn install --save-dev gulp-inline-import
Optionnal
Quick full installation
npm install --save-dev gulp gulp-cli gulp-inline-import
Or
yarn install --dev gulp gulp-cli gulp-inline-import
cate.js:
import './cry.js';
import './walk.js';
var cate = function() {
cry();
walk();
console.log('because I am a catto');
};
export default cate;
cry.js
var cry = function() {
console.log('meow >_<');
};
export default cry;
walk.js
var walk = function() {
console.log('Oh is that your keyboard? Let me show you something... Zzz...');
};
export default walk;
gulpfile.js
const gulp = require('gulp');
const inlineImport = require('gulp-inline-import');
gulp.task('inline', function() {
return gulp.src('./src/*.js')
.pipe( inlineImport() )
.pipe( gulp.dest('./src') );
});
Output of cate.js
var cry = function() {
console.log('meow >_<');
};
var walk = function() {
console.log('Oh is that your keyboard? Let me show you something... Zzz...');
};
var cate = function() {
cry();
walk();
console.log('because I am a catto');
};
export default cate;
Note
Node packages exists to remove the export statement, like the babel plugin babel-plugin-transform-remove-export .
option | type | required | default | possible values | description |
---|---|---|---|---|---|
verbose | Boolean | no | false | true,false | Enable step by step in-console debug information |
maxDepth | Integer | no | 3 | Number of times the plugin should go deep inside nested import statements. This prevent circular imports for instance. | |
allowImportExportEverywhere | Boolean | no | false | true,false | Let you use import and export statements in the middle of your code instead of strictly at the top or bottom. |