1.2.0 • Published 8 years ago

gulp-typescript-module-bundler v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

#gulp-typescript-module-bundler

Gulp middleware for typescript-module-bundler, a pre-processor tool used to combine TypeScript modules that have been split across multiple files.

Install

~ npm install gulp-typescript-module-bundler --save-dev

Usage Example

var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');
var tsModuleBundler = require('gulp-typescript-module-bundler');

gulp.task('scripts', () => {
    return gulp.src('src/*.ts')
        .pipe(sourcemaps.init())
        .pipe(tsModuleBundler())
        .pipe(ts({
            module: 'commonjs'
        }))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('dist'));
});

Output Example

├── src/
   ├── file1.ts ~ module Module1 {...}
   ├── file2.ts ~ module Module1 {...}
   ├── file3.ts ~ module Module2 {...}
   └── file4.ts ~ module Module2 {...}

├── dist/
   ├── Module1.js
   └── Module2.js

Rollup Example

This example demonstrates the ability to transform module based code to native browser without the use of any library or nasty code wrapping / polyfilling.

var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var ts = require('gulp-typescript');
var tsModuleBundler = require('gulp-typescript-module-bundler');
var rollup = require('gulp-rollup');

gulp.task('scripts', () => {
    return gulp.src('src/*.ts')
        .pipe(sourcemaps.init())
        .pipe(tsModuleBundler({
            moduleOutput: 'es6'
        }))
        .pipe(ts({
            module: 'es6',
            target: 'es5',
        }))
        .pipe(rollup({
            entry: 'src/file1.js',
            format: 'iife'
        }))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('dist'));
});

**Please note this example will only work with TypeScript 2.0+, see #6319 for more details.

Options

moduleOutput

Sets module output style.

  • 'enclosed' (default): wraps the module contents in a module enclosure.
  • 'export': wraps the module contents in a exported module enclosure.
  • 'traditionalExport': wraps the module contents in a module enclosure and exports module for traditional CommonJS and AMD workflow.
  • 'es6' / 'none': does not wrap the module contents.

passThroughExcludedFiles

Passes files down the stream that did not contain any modules to bundle.