lernetz-typescript-gulp-task

This node module that wraps several gulp plugins into a reusable gulp task with options to complie typscript code

This package has moved into the organisation scope. Use @lernetz/gulp-typescript-bundle instead
Last updated 10 months ago by lernetz-mich .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install lernetz-typescript-gulp-task 
SYNC missed versions from official npm registry.

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
}

Current Tags

  • 0.5.0                                ...           latest (10 months ago)

18 Versions

  • 0.5.0 [deprecated]           ...           10 months ago
  • 0.4.2 [deprecated]           ...           a year ago
  • 0.4.1 [deprecated]           ...           2 years ago
  • 0.4.0 [deprecated]           ...           2 years ago
  • 0.3.2 [deprecated]           ...           2 years ago
  • 0.2.2 [deprecated]           ...           2 years ago
  • 0.2.1 [deprecated]           ...           3 years ago
  • 0.2.0 [deprecated]           ...           3 years ago
  • 0.1.2 [deprecated]           ...           3 years ago
  • 0.1.1 [deprecated]           ...           3 years ago
  • 0.1.0 [deprecated]           ...           4 years ago
  • 0.0.3 [deprecated]           ...           4 years ago
  • 0.0.2-b                                ...           4 years ago
  • 0.0.2-a                                ...           4 years ago
  • 0.0.2 [deprecated]           ...           4 years ago
  • 0.0.1-a                                ...           4 years ago
  • 0.0.1 [deprecated]           ...           4 years ago
  • 0.0.0 [deprecated]           ...           4 years ago
Maintainers (1)
Downloads
Today 1
This Week 3
This Month 4
Last Day 2
Last Week 0
Last Month 24
Dependencies (9)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |