How do I get TypeScript to bundle a 3rd party lib from node_modules?

后端 未结 1 2114
谎友^
谎友^ 2021-02-20 10:52

I would like the TypeScript Compiler to use node_modules/firebase/firebase.d.ts to typecheck my code and also bundle node_modules/firebase/firebase.js

相关标签:
1条回答
  • 2021-02-20 11:41

    tsc is a compiler, not a bundler. This question expounds on bundling a bit.

    While developing in TypeScript, gulp + gulp-browserify can provide a watcher and bundler.

    With "module": "umd" in the 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']);
    });
    
    0 讨论(0)
提交回复
热议问题