0.5.0 • Published 5 years ago

lernetz-typescript-gulp-task v0.5.0

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

lernetz-typescript-gulp-task

This node module wraps several gulp plugins executions into one reusable gulp task. The main goal of the task is to compile a set of typescript files into a single js file. It automatically creates a minified version and injects the sourcemaps. It internally uses rollup with treeshaking for a smallest as possible filesize. Rollup is setup to bundle also npm packages. This allows to use npm packages in our source typescript. You need to install the required types for typescript see: https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/ And also install the library itself with npm so rollup can find and bundle it.

In the 0.4.x version with gulp 4.0 this module will automatically register two gulp tasks: ln:bundle, ln:minify. You can use them directly in your gulp file or from outside. See npx gulp --tasks.

Usage

The following example will compile the file Main.ts and bundle all its dependencies into to the output folder public. It creates the following js files:

  • main.js - the uncompressed js source
  • main.js.map - the sourcemap file
  • main.min.js - the minified js file The resulting js file exposes the exported functions/variables of Main.ts under the globalName: main.
var gulp = require('gulp');

// this will automatically register to gulp tasks: ln:bundle, ln:minify and returns them as gulp.series( 'ln:bundle', 'ln:minify' )
var bundle = require( 'lernetz-typescript-gulp-task' )( { dest:'public', src:'Main.ts', name:'main' } );

// either define your own task
gulp.task( 'bundle', bundle );

// or use it directly in your watch statement
gulp.task('default', function() {
    gulp.watch( 'typescript/**/*.ts', bundle );
    // or 
    gulp.watch( 'typescript/**/*.ts', gulp.series( 'ln:bundle', 'ln:minify' ) );
});

// or directly call:
// npx gulp ln:bundle
// npx gulp ln:minify

Options

The task accepts an parameter object with the following attributes:

{
    name: 'main', // the name of the js file to create and also the globalname 
	dest: 'public', // the destination used in gulp.dest( .. )
    src: './src/main.ts', // the source the the main typescript file
    rollup: {
        // the default input options used for rollup. see: https://rollupjs.org/guide/en#javascript-api
        inputOptions: {
            input: options.src, // autogenerated if not defined
            plugins: [
                typescript( { check:false } ),
                resolve( { jsnext: true, main: true, browser:true } ),
                commonjs(),
            ]
        },
        // the default output options used for rollup. see: https://rollupjs.org/guide/en#javascript-api
        outputOptions: { 
            file: options.dest + '/' + options.name + '.js', // autogenerated if not defined
            name: options.name,  // autogenerated if not defined
            format: 'iife',
            sourcemap: true
        }
    },
    uglify: {} // the default options for the ugify task: https://www.npmjs.com/package/gulp-uglify-es
}
0.5.0

5 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.2.2

6 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.3

9 years ago

0.0.2-b

9 years ago

0.0.2-a

9 years ago

0.0.2

9 years ago

0.0.1-a

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago