[英]Minify typescript into one JS file, keep the sourcemaps working using gulp
I've crawled all over the net for this one. 我已经在网上搜寻了这个。
I've thought about using --out, but there's a huge essay https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md specifying why that's a bad idea. 我已经考虑过使用--out了,但是有大量文章https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md指出为什么这是一个坏主意。
It says 它说
--out is really the job of some build tool. --out实际上是某些构建工具的工作。
but, doesn't really go further than that. 但是,并没有比这更进一步。 So, I have the following process so far: 因此,到目前为止,我有以下过程:
The first line in the transpiled file is: appEntryPoint.js: 编译文件的第一行是:appEntryPoint.js:
define(["require", "exports", "./example"], function (require, exports, example_1) {
I get: "Uncaught reference error, define is not defined". 我得到:“未捕获的引用错误,定义未定义”。 I tried to add require-js so it's loaded before this file, but that didn't work either. 我试图添加require-js,以便在此文件之前加载它,但这也不起作用。
So. 所以。 What are my options? 我有什么选择?
For reference, here's my gulpfile.js
: 供参考,这是我的gulpfile.js
:
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']);
只需使用gulp-concat
将所有*.js
文件合并为一个即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.