2016-11-18 17 views
0

我已經從A2創建了webpack build。這是一個包含我所有組件的大文件,並且此文件可以正常工作(如果我包含此文件而不是縮小版本),並且所有組件/視圖/模板都按預期工作。 但是我想用gulp醜化這個文件,並且縮小後的某些功能會丟失或無法正常工作,例如 - 某些html模板將不會呈現。 我想知道 - 我錯過了什麼,或者我的大嘴文件沒有正確設置? 這裏是:正確的方法來縮小Angular2文件

var gulp = require('gulp'), 
     aa_rename = require('gulp-rename'), 
     aa_uglify = require('gulp-uglify'), 
     aa_sourcemaps = require('gulp-sourcemaps'); 

gulp.task('aa-production', function() { 
    return gulp.src([ 
     'AppProductionLive/angular2live.js', 
    ]) 
     .pipe(aa_sourcemaps.init()) 
     .pipe(aa_rename('a2uglify.js')) 
     .pipe(aa_uglify()) 
     .pipe(aa_sourcemaps.write('./')) 
     .pipe(gulp.dest('AppProductionLive')); 
}); 

gulp.task('default', ['aa-production'], function() {}); 

看來,被精縮代碼時,有些東西失去了。 並且控制檯沒有顯示任何錯誤。

+1

看到微小的官方文檔更多配置選項/醜化()https://angular.io/docs/ts/latest/cookbook/aot-compiler.html#!#tree-shaking –

回答

0

使用webpack,你可以使用UglifyJsPlugin uglify代碼。檢查醜化JS對official usage documentation

const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin'); 

plugins: [ 
    // your other webpack plugin 

    new UglifyJsPlugin({ 
    beautify: false, //prod 
    mangle: { 
     screw_ie8: true, 
     keep_fnames: true 
    }, //prod 
    compress: { 
     screw_ie8: true 
    }, //prod 
    comments: false //prod 
    }) 
] 
相關問題