[英]How to concat & minify an angular2 application?
I would like to concat & minify an angular2 application. 我想连续和缩小angular2应用程序。 What I did was first concatenating all my *.js files (boot.js, application.js then all components) in one file and injected it to my index.html.
我所做的是首先将我的所有* .js文件(boot.js,application.js然后所有组件)连接到一个文件中,并将其注入我的index.html。 I also deleted the
我也删除了
<script>
System.config({
packages: {
app: {
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
and replaced it with my 并用我的替换它
<script src="js/allMyConcatFilesIntoOne.js"></script>
But I got the error, that require is missing/unknown. 但是我得到了错误,需要丢失/未知。
How are angular2 applications filled into one file? angular2应用程序如何填充到一个文件中? Do I have to gather all typescript files first and then concat and then compile it via gulp?
我是否必须首先收集所有打字稿文件然后连接然后通过gulp编译?
Regards 问候
Tenoda Tenoda
Use a gulpfile.js like this: 使用像这样的gulpfile.js:
/// <binding Clean='clean' />
"use strict";
var gulp = require("gulp"),
rimraf = require("rimraf"),
concat = require("gulp-concat"),
cssmin = require("gulp-cssmin"),
uglify = require("gulp-uglify"),
tsc = require("gulp-typescript");
var webroot = "./wwwroot/";
var paths = {
js: webroot + "js/**/*.js",
ts: webroot + "app/**/*.ts",
minJs: webroot + "js/**/*.min.js",
css: webroot + "css/**/*.css",
minCss: webroot + "css/**/*.min.css",
concatJsDest: webroot + "js/site.min.js",
concatCssDest: webroot + "css/site.min.css"
};
gulp.task("clean:js", function (cb) {
rimraf(paths.concatJsDest, cb);
});
gulp.task("clean:css", function (cb) {
rimraf(paths.concatCssDest, cb);
});
gulp.task("clean", ["clean:js", "clean:css"]);
gulp.task("min:js", function () {
return gulp.src([paths.js, "!" + paths.minJs], { base: "." })
.pipe(concat(paths.concatJsDest))
.pipe(uglify())
.pipe(gulp.dest("."));
});
gulp.task("min:css", function () {
return gulp.src([paths.css, "!" + paths.minCss])
.pipe(concat(paths.concatCssDest))
.pipe(cssmin())
.pipe(gulp.dest("."));
});
gulp.task("min", ["min:js", "min:css"]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.