我工作在生產建設一個角2應用程序和在嘗試使用角2 AOT的構建過程,以減小封裝尺寸(記錄here)角2 AOT構建生產sourcemaps內聯和文件
我通過aot編譯器CLI和彙總CLI獲得了構建,並且我得到了我期待的輸出。 我的bundle.js文件是〜2k。,還有一個伴隨的源映射文件。好極了!
接下來,我試圖將rollup合併到我現有的gulp版本中。一切正常,除了源映射內置在捆綁使其超過2MB。此外,還會生成一個源映射文件。當我手動刪除內聯源地圖時,我的包大小下降到〜2k。
我的問題是如何讓我的bundle.js在沒有內聯源地圖的情況下生成?
我試過的東西:搜索SO,搜索Angular2 docs,rollup-stream docs和gulp-sourcemap docs。我還沒有找到任何具體解決這個問題的東西。
下面是相關的配置文件
AOT特定tsconfig文件(tsconfig-aot.json):
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"node_modules/@types/"
]
},
"include": [
"app/**/*.ts"
],
"exclude": [
"node_modules",
"wwwroot"
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit": true
}
}
彙總配置(我試過註釋掉蒸餾水和sourceMapFile文件路徑來查看是否拋棄了一口氣,但它沒有效果):
import rollup from 'rollup';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';
let config = {
entry: 'app/app-aot.js',
dest: 'wwwroot/dist/bundle.js', // output a single application bundle
sourceMap: true,
sourceMapFile: 'wwwroot/dist/bundle.js.map',
format: 'iife',
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: ['node_modules/rxjs/**']
}),
uglify()
]
}
//paths are relative to the execution path
export default config
而一飲而盡文件:
var gulp = require('gulp');
var del = require('del');
var helpers = require('./config/helpers');
var exec = require('child_process').exec;
var merge = require('merge-stream');
var rename = require('gulp-rename');
var rollup = require('rollup-stream');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var sourcemap = require('gulp-sourcemaps');
var paths = {
app: helpers.root('app/**/*'),
bootstrap: helpers.root('app/assets/bootstrap/'),
images: helpers.root('app/assets/images/')
};
gulp.task('clean', function() {
return del(['wwwroot/**/*']);
});
gulp.task('clean-aot', ['clean'], function() {
return del(['aot/**/*']);
});
gulp.task('bundle-aot', ['clean', 'clean-aot'], function(callBack) {
exec('\"node_modules/.bin/ngc\" -p tsconfig-aot.json', function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callBack(err);
});
});
gulp.task('bundle-rollup', ['bundle-aot'], function() {
return rollup('rollup-config.js')
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemap.init({ loadMaps: true }))
.pipe(sourcemap.write('.'))
.pipe(gulp.dest('wwwroot/dist'));
});
gulp.task('bundle-copy-files', ['bundle-rollup'], function() {
var bsCss = gulp.src(paths.bootstrap + '/css/*.min.css').pipe(gulp.dest('wwwroot/assets/bootstrap/css/'));
var bsFonts = gulp.src(paths.bootstrap + '/fonts/*').pipe(gulp.dest('wwwroot/assets/bootstrap/fonts/'));
var images = gulp.src(paths.images + '*').pipe(gulp.dest('wwwroot/assets/images/'));
var shim = gulp.src('node_modules/core-js/client/shim.min.js').pipe(gulp.dest('wwwroot/'));
var zone = gulp.src('node_modules/zone.js/dist/zone.min.js').pipe(gulp.dest('wwwroot/'));
var index = gulp.src('app/index-aot.html').pipe(rename('index.html')).pipe(gulp.dest('wwwroot/'));
return merge(bsCss, bsFonts, images, shim, zone, index);
});
gulp.task('bundle', ['clean', 'clean-aot', 'bundle-aot', 'bundle-rollup', 'bundle-copy-files']);
編輯:我沒有找到具有一飲而盡執行彙總與CLI一種解決方法。儘管如此,我仍然想知道我在吞嚥或彙總配置中做錯了什麼。
gulp.task('bundle-rollup', ['bundle-aot'], function(callBack) {
exec('\"node_modules/.bin/rollup\" -c rollup-config.js', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
callBack(err);
});
});