Skip to content

Instantly share code, notes, and snippets.

@mkusher
Last active October 14, 2019 14:50
Show Gist options
  • Save mkusher/2a6a752b8fb30eef16c2 to your computer and use it in GitHub Desktop.
Save mkusher/2a6a752b8fb30eef16c2 to your computer and use it in GitHub Desktop.
Browserify project with tsify
var gulp = require("gulp");
var browserify = require("browserify");
var babelify = require("babelify");
var source = require("vinyl-source-stream");
var config = {
src: "index.js",
filename: "bundle.js",
dest: "./"
};
var extensions = ['.js', '.ts', '.json'];
var b = browserify({extensions: extensions});
b
.plugin('tsify', {target: 'es6'})
.transform(babelify.configure({
extensions: extensions
}))
.add(config.src)
.bundle()
// log errors if they happen
.on("error", function(e){
console.log(e.message);
throw e;
})
.pipe(source(config.filename))
.pipe(gulp.dest(config.dest));
export default class Ctrl {
name: string;
constructor(name: string){
this.name = name;
}
login() {
return "Hello, " + this.name;
}
}
import Ctrl from './ctrl.ts';
let ctrl = new Ctrl("Dolly");
console.log(ctrl.login());
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"target": "es6"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment