The simplest plugin to build scripts supporting base import/export expressions. Suitable for small simple vanilla javascript projects.
Consider example section to quick jump into.
npm install Sanshain/gulp-packager
or
npm i gulp-packager
For descriptive reasons the examples below assumes the following task in gulpfile.js
:
gulp.task('build', function() {
let src = './samples/**/init.ts';
return gulp.src(src)
.pipe(cache(src))
.pipe(rename((path) => path.extname = '.js'))
.pipe(packager({ release : true }))
// .pipe(ts())
.pipe(gulp.dest('./samples'))
});
gulp example
__common.ts
file:
export let months = ['Jan', 'Feb', 'Mar', 'Apr', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
let r = 7
export var a = 66;
export function Ads(arg){}
function asd(){}
export function f(){}
export class Asde{constructor(){}}
and init.ts
:
import { months, Ads } from "./button/__common"
var a = months;
var c = 754;
console.log(a);
turn out the content inside init.js
in the same directory:
const $$button$__commonExports = (function (exports) {
let months = ['Jan', 'Feb', 'Mar', 'Apr', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
let r = 7
var a = 66;
function Ads(arg){}
function asd(){}
function f(){}
class Asde{constructor(){}}
exports = { months, a, Ads, f, Asde };
return exports
})({})
const { months, Ads } = $$button$__commonExports;
var a = months;
var c = 754;
console.log(a);
const build = require('gulp-packager/pack').integrate
const r = build("samples/init.ts")
console.log(r);
- does not currently support importing npm packages. If your needs are beyond the scope of this package, suggest using rollup.
- no sourcemap support (may be TODO)
- not supported combined recipes of imports like following forms:
import defaultExport, * as name from "./module-name";
import defaultExport, { export } from "./module-name";
release : true
- removes comments all over inside built file
Besides using import * as name from './...'
, import {name} from './...'
you can also use `import './...``.
But this option does not intended for types/class imports - what will you get a hint about in this case
If you need to skip some import
statements, you should to wrap it into following comment with lazy
keyword:
/*-lazy*/
import * as lazy from "./__common"
/*lazy-*/
In this case the multiple comments with lazy
word in output file will be removed including all import
content between them