How do I get TypeScript to bundle a third party library with node_modules?
I would like the TypeScript compiler to use node_modules/firebase/firebase.d.ts
for the typecheck of my code, and also link node_modules/firebase/firebase.js
to some files where I have imported things from firebase. I realize there are several options that will do this for me, but I would like to keep a minimal developer environment.
I have set "moduleResolution": "node"
in mine tsconfig.json
, which imports definitions and type validates my code the way I want. I also added "isolatedModules": true
in an attempt to link the actual code to each of my goals, but the generated code does not link firebase.js as I would like. Is there a compiler option "module"
that will do this for me, or should I add something else?
If I need another tool in my dev process, what's the simplest addition to tsc
that will bundle each of my JS files + their dependencies into one js package?
source to share
tsc
is a compiler, not a coherent one. This question poses a little bit.
When developing in TypeScript, gulp
+ gulp-browserify
can provide an observer and a binder.
With "module": "umd"
in compiler options, this gulpfile.js
will do the rest:
var gulp = require('gulp');
var ts = require('gulp-typescript');
var browserify = require('gulp-browserify');
gulp.task('default', function () {
return gulp.src('src/*.ts')
.pipe(ts.createProject('tsconfig.json')())
.pipe(browserify())
.pipe(gulp.dest('dist/gen'));
});
gulp.task('watch', ['default'], function () {
gulp.watch('src/*.ts', ['default']);
});
source to share