私はgulpを初めて使用しているので、おそらくかなり一般的なシナリオです。私がやりたいことは、typescriptをjavascriptにコンパイルして、ソースマップを作成してからuglifyを実行することです。 ugliyfiedとnonuuglified jsのソースマップを用意したいと思います。私はachiveしようとしている何Gulp:縮小化されたスクリプトと非縮小化されたスクリプトの両方のソースマップを生成する
は、以下のファイル構造である:
framework.js
framework.js.map < this won't work
framework.min.js
framework.min.js.map
これは私の一気の作業です:あなたが見ることができるように
var gulp = require('gulp'),
uglify = require('gulp-uglify')
ts = require("gulp-typescript")
sourcemaps = require('gulp-sourcemaps')
rename = require('gulp-rename');
var tsProject = ts.createProject("tsconfig.json");
gulp.task('typescript', function(){
tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject()).js
.pipe(sourcemaps.write('.')) // Write sourcemap for non-minified version
.pipe(gulp.dest("dist"))
.pipe(uglify()) // Code will fail here
.pipe(rename({suffix:'.min'}))
.pipe(sourcemaps.write('.')) // Write sourcemap for minified version.
.pipe(gulp.dest("dist"));
});
gulp.task('default', ['typescript']);
、私は(sourcemaps.writeを実行していますよ)を2回実行して2つの異なるファイルを取得します。これは、()の呼び出しは、ファイルの縮小さバージョンの正しいsourcemapになりますsourcemap.writeの最初のものを残してくれエラー
tream.js:74
throw er; // Unhandled stream error in pipe.
^GulpUglifyError: unable to minify JavaScript
at createError (C:\Users\alexa\Dropbox\code\Web\mhadmin\framework\node_modules\gulp-uglify\lib\create-error.js:6:14)
を与えます。
これを修正する方法はありますか?
編集:私はgulp.destする複数の呼び出しで複数のsourcemapsを書く必要があり、これは(正確にgulp: uglify and sourcemapsの複製ではありません)
[gulp:uglifyとsourcemaps]の複製があります(http://stackoverflow.com/questions/32502678/gulp-uglify-and-sourcemaps) – user3272018