Saya mendapat masalah yang sama, dan solusi saya terlihat seperti ini:
export module Module1 {
export class Module1{
greating(){ return 'hey from Module1'}
}
}
import {Module1} from './../module1/module1';
export module Module2{
export class Module2{
greating(){
let m1 = new Module1.Module1()
return 'hey from Module2 + and from loaded Model1: '+ m1.greating();
}
}
}
Sekarang kita bisa menggunakannya di sisi server:
import {Module2} from './module2/module2';
export module Server {
export class Server{
greating(){
let m2 = new Module2.Module2();
return "hello from server & loaded modules: " + m2.greating();
}
}
}
exports.Server = Server;
var Server = require('./server').Server.Server;
var server = new Server();
console.log(server.greating());
Dan di sisi klien juga:
import {Module2} from './../../../module2/module2';
document.body.onload = function(){
let m2 = new Module2.Module2();
alert(m2.greating());
}
extends layout
block content
h1= title
p Welcome to #{title}
script(src='main.js')
the main.js-file created by gulp-task 'browserify' below in the gulpfile.js
Dan, tentu saja, file gulp untuk semua ini:
var gulp = require('gulp'),
ts = require('gulp-typescript'),
runSequence = require('run-sequence'),
browserify = require('gulp-browserify'),
rename = require('gulp-rename');
gulp.task('default', function(callback) {
gulp.task('ts1', function() {
return gulp.src(['./module1/module1.ts'])
.pipe(ts())
.pipe(gulp.dest('./module1'))
});
gulp.task('ts2', function() {
return gulp.src(['./module2/module2.ts'])
.pipe(ts())
.pipe(gulp.dest('./module2'))
});
gulp.task('ts3', function() {
return gulp.src(['./public/javascripts/index/index.ts'])
.pipe(ts())
.pipe(gulp.dest('./public/javascripts/index'))
});
gulp.task('browserify', function() {
return gulp.src('./public/javascripts/index/index.js', { read: false })
.pipe(browserify({
insertGlobals: true
}))
.pipe(rename('main.js'))
.pipe(gulp.dest('./public/javascripts/'))
});
runSequence('ts1', 'ts2', 'ts3', 'browserify', callback);
})
Diperbarui.
Tentu saja, tidak perlu mengompilasi file skrip secara terpisah.
runSequence(['ts1', 'ts2', 'ts3'], 'browserify', callback)
bekerja dengan sempurna.