ts-universal

A simple gulp plugin that makes it possible to use typescript modules painlessly on browser and on server. Say no webpack!

ISC 16 个版本
安装
npm install ts-universal
yarn add ts-universal
pnpm add ts-universal
bun add ts-universal
README

ts-universal (gulp plugin)

A simple gulp plugin that makes it possible to use typescript modules painlessly on browser and on server. Say no webpack!

Coding

Features

  • Converts typescript output into a unversal module (1 file)
  • Exposes targets naturaly to window or NodeJS
  • 100% Typescript sourcemaps support
  • Simplicity - 4 variables to configure
  • No extra libraries required!

How it works

tsUniversal works with AMD typescript importer. But instead of having AMD, tsUniversal creates a tiny header that does magic!

Try it now!

Install it

npm install ts-universal --save-dev

Gulp Build example

const gulp = require('gulp');
const rename = require("gulp-rename");
const ts = require('gulp-typescript');
const concat = require('gulp-concat');
const tsUniversal = require("./index.js");
const sourcemaps = require('gulp-sourcemaps');
const tsProject = ts.createProject('example/tsconfig.json', {});
gulp.task('default', function() {
    var toResult = gulp.src('example/**/*.ts')
        .pipe(sourcemaps.init())
        .pipe(tsProject())
    return toResult.js.pipe(tsUniversal('build/', {
        name: 'my-lib-name',
        expose: 'root',
        expose2window: true,
        consume: ["controllers/", "routes/"]
    }))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('build/'));
});

Win

out.js can be required with "root.ts" exposed both to front end and backend!

To test in on server:

node build/test.js

On browser -> just open build/index.html in your browser!

版本列表
2.0.5 2016-10-06
2.0.4 2016-10-06
2.0.3 2016-10-05
2.0.2 2016-09-29
2.0.1 2016-09-29
2.0.0 2016-09-28
1.0.9 2016-09-22
1.0.8 2016-09-20
1.0.7 2016-09-20
1.0.6 2016-08-19
1.0.5 2016-08-19
1.0.4 2016-08-19
1.0.3 2016-08-18
1.0.2 2016-08-18
1.0.1 2016-08-18
1.0.0 2016-08-18