首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将类型记录缩小为一个JS文件,保持源代码映射使用gulp

将类型记录缩小为一个JS文件,保持源代码映射使用gulp
EN

Stack Overflow用户
提问于 2016-02-26 16:35:49
回答 1查看 1.9K关注 0票数 2

我已经爬遍了这张网。

我想过使用

上面写着

但是,没有比这更远的了。因此,到目前为止,我有以下的过程:

  1. 把打字稿写好
  2. 编写打字本
  3. 构建源代码映射
  4. 将编译好的类型记录导入另一个目录(生成)
  5. 将所有bower添加到index.html文件中
  6. Serve index.html指向appEntryPoint.js,它只是一个JS文件,它调用项目其余部分中的一些内容。

转移文件中的第一行是: appEntryPoint.js:

代码语言:javascript
复制
define(["require", "exports", "./example"], function (require, exports, example_1) {

我得到:“未定义的参考错误,定义是没有定义的”。我试图添加-js,以便在这个文件之前加载它,但这也不起作用。

所以。我有什么选择?

  1. 我可以强制打字稿问,只是使用,要求,并包括从其他文件的任何需要?
  2. 我是否可以将所有的类型记录缩小到一个JS文件中,然后仍然可以使用源代码映射?如果是的话,怎么做?

供参考,这是我的gulpfile.js

代码语言:javascript
复制
var gulp = require('gulp');
var tsc = require('gulp-typescript');
var tslint = require('gulp-tslint');
var config = require('./gulpfile.config')();
var sourcemaps = require('gulp-sourcemaps');
var browsersync = require('browser-sync');
var superstatic = require('superstatic');
var usemin = require("gulp-usemin");
var uglify = require("gulp-uglify");
var reload      = browsersync.reload;
var wiredep = require("wiredep").stream;

gulp.task('ts-lint', function(){
  return gulp.src(config.allTs)
    .pipe(tslint())
    .pipe(tslint.report('prose', {
      emitError : false
    }));
});

gulp.task('compile-ts', function(){
  var sourceTsFiles = [
    config.allTs,
    config.typings
  ];

  var tsResult = gulp
    .src(sourceTsFiles)
    .pipe(sourcemaps.init())
    .pipe(tsc({
        module: "amd",
        target: "ES5",
        declarationFiles: false,
        emitError: false,
        emitDecoratorMetadata: true,
      outDir : config.tsOutputPath
    }));

  return tsResult.js
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(config.tsOutputPath))
    .pipe(reload({stream:true}));
});

gulp.task('serve', ['ts-lint', 'compile-ts', 'bower'], function() {
    gulp.watch([config.allTs], ['ts-lint', 'compile-ts']);

    browsersync({
        port: 3000,
        files: ['index.html', '**/*.js'],
        injectChanges: true,
        logFileChanges: false,
        logLevel: 'silent',
        notify: true,
        reloadDelay: 0,
        server: {
            baseDir: config.browsersyncpath,
            middleware: superstatic({ debug: false})
        }
    });
});



gulp.task("bower", function () {
    gulp.src("index.html")
        .pipe(wiredep())
        .pipe(gulp.dest("build"));
});

// gulp.task("minify", function () {
//  return gulp.src("build/index.html")
//      .pipe(usemin({
//          assetsDir: config.tsOutputPath,
//          js: [uglify(), "concat"]
//  }))
//   .pipe(gulp.dest(config.tsOutputPath));
// });

gulp.task('default', ['serve']);
EN

回答 1

Stack Overflow用户

发布于 2016-02-26 17:59:54

只需使用gulp-concat将所有*.js文件合并为一个。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35657046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档