mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 01:54:08 +03:00
Fix minified file deps: minify via systemjs builder
This commit is contained in:
parent
332b585f3f
commit
fb9f0fbe97
|
@ -10,10 +10,10 @@ var concat = require('gulp-concat');
|
||||||
var gulp = require('gulp');
|
var gulp = require('gulp');
|
||||||
var sass = require('gulp-sass');
|
var sass = require('gulp-sass');
|
||||||
var replace = require('gulp-replace');
|
var replace = require('gulp-replace');
|
||||||
var uglify = require('gulp-uglify');
|
|
||||||
var rename = require('gulp-rename');
|
var rename = require('gulp-rename');
|
||||||
|
|
||||||
paths.redocBuilt = path.join(paths.output, paths.outputName) + '.js';
|
paths.redocBuilt = path.join(paths.output, paths.outputName);
|
||||||
|
|
||||||
gulp.task('build', function (callback) {
|
gulp.task('build', function (callback) {
|
||||||
return runSequence(
|
return runSequence(
|
||||||
'clean',
|
'clean',
|
||||||
|
@ -31,8 +31,8 @@ gulp.task('buildDev', function (callback) {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
gulp.task('bundle', ['bundleSfx', 'concatDeps']);
|
gulp.task('bundle', ['buildStatic', 'concatDeps']);
|
||||||
gulp.task('bundleProd', ['bundle', 'uglify']);
|
gulp.task('bundleProd', ['bundle', 'buildStaticMin', 'concatDepsMin']);
|
||||||
|
|
||||||
gulp.task('inlineTemplates', ['sass'], function() {
|
gulp.task('inlineTemplates', ['sass'], function() {
|
||||||
return gulp.src(paths.source, { base: './' })
|
return gulp.src(paths.source, { base: './' })
|
||||||
|
@ -41,21 +41,16 @@ gulp.task('inlineTemplates', ['sass'], function() {
|
||||||
.pipe(gulp.dest(paths.tmp));
|
.pipe(gulp.dest(paths.tmp));
|
||||||
});
|
});
|
||||||
|
|
||||||
// produces minimized verstion of sfx bundle
|
|
||||||
gulp.task('uglify', ['concatDeps'], function() {
|
|
||||||
return gulp.src(paths.redocBuilt)
|
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(uglify())
|
|
||||||
.pipe(rename(paths.outputName + '.min.js'))
|
|
||||||
.pipe(sourcemaps.write('./'))
|
|
||||||
.pipe(gulp.dest(paths.output));
|
|
||||||
});
|
|
||||||
|
|
||||||
var JS_DEV_DEPS = [
|
var JS_DEV_DEPS = [
|
||||||
'node_modules/zone.js/dist/zone-microtask.js',
|
'node_modules/zone.js/dist/zone-microtask.js',
|
||||||
'node_modules/reflect-metadata/Reflect.js'
|
'node_modules/reflect-metadata/Reflect.js'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var JS_DEV_DEPS_MIN = [
|
||||||
|
'node_modules/zone.js/dist/zone-microtask.min.js',
|
||||||
|
'node_modules/reflect-metadata/Reflect.js'
|
||||||
|
]
|
||||||
|
|
||||||
gulp.task('sass', function () {
|
gulp.task('sass', function () {
|
||||||
return gulp.src(paths.scss, { base: './' })
|
return gulp.src(paths.scss, { base: './' })
|
||||||
.pipe(sass.sync().on('error', sass.logError))
|
.pipe(sass.sync().on('error', sass.logError))
|
||||||
|
@ -63,15 +58,31 @@ gulp.task('sass', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
// concatenate angular2 deps
|
// concatenate angular2 deps
|
||||||
gulp.task('concatDeps', ['bundleSfx'], function() {
|
gulp.task('concatDeps', ['buildStatic'], function() {
|
||||||
gulp.src(JS_DEV_DEPS.concat([paths.redocBuilt]))
|
return concatDeps(JS_DEV_DEPS, paths.redocBuilt + '.js');
|
||||||
.pipe(sourcemaps.init({loadMaps: true}))
|
|
||||||
.pipe(concat(paths.outputName + '.js'))
|
|
||||||
.pipe(sourcemaps.write('.'))
|
|
||||||
.pipe(gulp.dest(paths.output))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('bundleSfx', ['inlineTemplates'], function(cb) {
|
gulp.task('concatDepsMin', ['buildStatic'], function() {
|
||||||
|
return concatDeps(JS_DEV_DEPS_MIN, paths.redocBuilt + '.min.js');
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('buildStatic', ['inlineTemplates'], function(cb) {
|
||||||
|
bundle(paths.redocBuilt + '.js', false, cb);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('buildStaticMin', ['inlineTemplates'], function(cb) {
|
||||||
|
bundle(paths.redocBuilt + '.min.js', true, cb);
|
||||||
|
});
|
||||||
|
|
||||||
|
function concatDeps(deps, file) {
|
||||||
|
return gulp.src(deps.concat([file]))
|
||||||
|
.pipe(sourcemaps.init({loadMaps: true}))
|
||||||
|
.pipe(concat(file))
|
||||||
|
.pipe(sourcemaps.write('.'))
|
||||||
|
.pipe(gulp.dest('.'))
|
||||||
|
}
|
||||||
|
|
||||||
|
function bundle(outputFile, minify, cb) {
|
||||||
fs.existsSync('dist') || fs.mkdirSync('dist');
|
fs.existsSync('dist') || fs.mkdirSync('dist');
|
||||||
var builder = new Builder('./', 'system.config.js');
|
var builder = new Builder('./', 'system.config.js');
|
||||||
builder.config({
|
builder.config({
|
||||||
|
@ -80,8 +91,8 @@ gulp.task('bundleSfx', ['inlineTemplates'], function(cb) {
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.buildStatic(path.join(paths.tmp, paths.sourceEntryPoint),
|
.buildStatic(path.join(paths.tmp, paths.sourceEntryPoint),
|
||||||
paths.redocBuilt,
|
outputFile,
|
||||||
{ format:'amd', sourceMaps: true, lowResSourceMaps: true }
|
{ format:'amd', sourceMaps: true, lowResSourceMaps: true, minify: minify }
|
||||||
)
|
)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
cb();
|
cb();
|
||||||
|
@ -89,4 +100,4 @@ gulp.task('bundleSfx', ['inlineTemplates'], function(cb) {
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
cb(new Error(err));
|
cb(new Error(err));
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
|
@ -65,7 +65,6 @@
|
||||||
"gulp-replace": "^0.5.4",
|
"gulp-replace": "^0.5.4",
|
||||||
"gulp-sass": "^2.1.1",
|
"gulp-sass": "^2.1.1",
|
||||||
"gulp-sourcemaps": "^1.6.0",
|
"gulp-sourcemaps": "^1.6.0",
|
||||||
"gulp-uglify": "^1.5.1",
|
|
||||||
"isparta": "^4.0.0",
|
"isparta": "^4.0.0",
|
||||||
"istanbul": "github:gotwarlost/istanbul#source-map",
|
"istanbul": "github:gotwarlost/istanbul#source-map",
|
||||||
"jasmine-core": "^2.4.1",
|
"jasmine-core": "^2.4.1",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user