Feature/#35 build tools #36
161
gulpfile.js
161
gulpfile.js
|
@ -0,0 +1,161 @@
|
|||
Serraniel
commented
Review
```suggestion
debug: isDev
```
```suggestion
debug: isDev
```
|
||||
const gulp = require('gulp');
|
||||
```suggestion
debug: isDev
```
|
||||
const cssnano = require('cssnano')
|
||||
```suggestion
debug: isDev
```
|
||||
const gulpLoadPlugins = require('gulp-load-plugins')
|
||||
```suggestion
debug: isDev
```
|
||||
const uglify = require('gulp-uglify-es').default;
|
||||
```suggestion
debug: isDev
```
|
||||
const del = require('del');
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
const $ = gulpLoadPlugins()
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
$.sass.compiler = require('sass');
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
/* ============================================================================
|
||||
```suggestion
debug: isDev
```
|
||||
Base consts
|
||||
```suggestion
debug: isDev
```
|
||||
============================================================================ */
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
// Project sources
|
||||
```suggestion
debug: isDev
```
|
||||
const src = {
|
||||
```suggestion
debug: isDev
```
|
||||
root: 'src',
|
||||
```suggestion
debug: isDev
```
|
||||
styles: 'src/stylesheets',
|
||||
```suggestion
debug: isDev
```
|
||||
scripts: 'src/javascript',
|
||||
```suggestion
debug: isDev
```
|
||||
images: 'src/images',
|
||||
```suggestion
debug: isDev
```
|
||||
}
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
// Build path
|
||||
```suggestion
debug: isDev
```
|
||||
const tmp = {
|
||||
```suggestion
debug: isDev
```
|
||||
root: '.tmp',
|
||||
```suggestion
debug: isDev
```
|
||||
styles: '.tmp/stylesheets',
|
||||
```suggestion
debug: isDev
```
|
||||
scripts: '.tmp/javascript',
|
||||
```suggestion
debug: isDev
```
|
||||
images: '.tmp/images',
|
||||
```suggestion
debug: isDev
```
|
||||
vendor: '.tmp/libs',
|
||||
```suggestion
debug: isDev
```
|
||||
maps: '../sourcemaps',
|
||||
```suggestion
debug: isDev
```
|
||||
}
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
// Dist path
|
||||
```suggestion
debug: isDev
```
|
||||
const dist = {
|
||||
```suggestion
debug: isDev
```
|
||||
root: 'dist',
|
||||
```suggestion
debug: isDev
```
|
||||
styles: 'dist/stylesheets',
|
||||
```suggestion
debug: isDev
```
|
||||
scripts: 'dist/javascript',
|
||||
```suggestion
debug: isDev
```
|
||||
images: 'dist/images',
|
||||
```suggestion
debug: isDev
```
|
||||
vendor: 'dist/libs',
|
||||
```suggestion
debug: isDev
```
|
||||
maps: 'dist/sourcemaps',
|
||||
```suggestion
debug: isDev
```
|
||||
}
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
// Build mode
|
||||
```suggestion
debug: isDev
```
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
```suggestion
debug: isDev
```
|
||||
const isDev = !isProd;
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
/* ============================================================================
|
||||
```suggestion
debug: isDev
```
|
||||
Build tasks
|
||||
```suggestion
debug: isDev
```
|
||||
============================================================================ */
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.task('styles', () => {
|
||||
```suggestion
debug: isDev
```
|
||||
return gulp.src(`${src.styles}/*.scss`)
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.plumber())
|
||||
```suggestion
debug: isDev
```
|
||||
// sourcemap initialization
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.if(isDev, $.sourcemaps.init()))
|
||||
```suggestion
debug: isDev
```
|
||||
// sass compilation
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.sass.sync({
|
||||
```suggestion
debug: isDev
```
|
||||
outputStyle: 'expanded',
|
||||
```suggestion
debug: isDev
```
|
||||
precision: 7,
|
||||
```suggestion
debug: isDev
```
|
||||
includePaths: ['.'],
|
||||
```suggestion
debug: isDev
```
|
||||
}).on('error', $.sass.logError))
|
||||
```suggestion
debug: isDev
```
|
||||
// autoprefix
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.autoprefixer())
|
||||
```suggestion
debug: isDev
```
|
||||
// out stream size
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.size({
|
||||
```suggestion
debug: isDev
```
|
||||
showFiles: true
|
||||
```suggestion
debug: isDev
```
|
||||
}))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe(gulp.dest(tmp.styles))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.rename({ suffix: '.min' }))
|
||||
```suggestion
debug: isDev
```
|
||||
// minimize and optimize
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.if('*.css', $.postcss([
|
||||
```suggestion
debug: isDev
```
|
||||
cssnano({
|
||||
```suggestion
debug: isDev
```
|
||||
safe: true,
|
||||
```suggestion
debug: isDev
```
|
||||
autoprefixer: false,
|
||||
```suggestion
debug: isDev
```
|
||||
zindex: false,
|
||||
```suggestion
debug: isDev
```
|
||||
reduceIdents: {
|
||||
```suggestion
debug: isDev
```
|
||||
keyframes: true,
|
||||
```suggestion
debug: isDev
```
|
||||
},
|
||||
```suggestion
debug: isDev
```
|
||||
})
|
||||
```suggestion
debug: isDev
```
|
||||
])))
|
||||
```suggestion
debug: isDev
```
|
||||
// out stream size
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.size({
|
||||
```suggestion
debug: isDev
```
|
||||
showFiles: true
|
||||
```suggestion
debug: isDev
```
|
||||
}))
|
||||
```suggestion
debug: isDev
```
|
||||
// write sourcemaps
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.if(isDev, $.sourcemaps.write(tmp.maps)))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe(gulp.dest(tmp.styles))
|
||||
```suggestion
debug: isDev
```
|
||||
})
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.task('scripts', () => {
|
||||
```suggestion
debug: isDev
```
|
||||
return gulp.src(`${src.scripts}/**/*.js`)
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.plumber())
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.if(isDev, $.sourcemaps.init()))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.babel())
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.rename({ suffix: '.min' }))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.if('*.js', uglify({ compress: { drop_console: isProd, drop_debugger: isProd } })))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.size({
|
||||
```suggestion
debug: isDev
```
|
||||
showFiles: true,
|
||||
```suggestion
debug: isDev
```
|
||||
}))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.if(isDev, $.sourcemaps.write(tmp.maps)))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe(gulp.dest(`${tmp.scripts}`))
|
||||
```suggestion
debug: isDev
```
|
||||
})
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.task('images', () => {
|
||||
```suggestion
debug: isDev
```
|
||||
return gulp.src(`${src.images}/**/*`)
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.plumber())
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.imagemin([
|
||||
```suggestion
debug: isDev
```
|
||||
$.imagemin.gifsicle({ interlaced: true }),
|
||||
```suggestion
debug: isDev
```
|
||||
$.imagemin.mozjpeg({ progressive: true }),
|
||||
```suggestion
debug: isDev
```
|
||||
$.imagemin.optipng(),
|
||||
```suggestion
debug: isDev
```
|
||||
$.imagemin.svgo({ plugins: [{ cleanupIDs: false }] })
|
||||
```suggestion
debug: isDev
```
|
||||
]))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe($.size({ title: 'images' }))
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe(gulp.dest(tmp.images))
|
||||
```suggestion
debug: isDev
```
|
||||
})
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
/* ============================================================================
|
||||
```suggestion
debug: isDev
```
|
||||
Clean
|
||||
```suggestion
debug: isDev
```
|
||||
============================================================================ */
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.task('clean:build', del.bind(null, [tmp.root]))
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.task('clean:dist', del.bind(null, [dist.root], { force: true })) // Das Force brauchen wir, da das Assets Verzeichnis außerhalb des Working Directories ist.
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.task('clean', gulp.series('clean:build', 'clean:dist'))
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
/* ============================================================================
|
||||
```suggestion
debug: isDev
```
|
||||
BUILD CLEAN ALL
|
||||
```suggestion
debug: isDev
```
|
||||
============================================================================ */
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.task('build', gulp.series('clean:build', 'images', 'scripts', 'styles'));
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
/* ============================================================================
|
||||
```suggestion
debug: isDev
```
|
||||
DIST CLEAN ALL
|
||||
```suggestion
debug: isDev
```
|
||||
============================================================================ */
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.task('dist:copy', (done) => {
|
||||
```suggestion
debug: isDev
```
|
||||
// copy vendor
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.src(`${tmp.vendor}/**/*`)
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe(gulp.dest(dist.vendor))
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
// copy images
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.src(`${tmp.images}/**/*`)
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe(gulp.dest(dist.images))
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
// copy scripts
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.src(`${tmp.scripts}/**/*.{min.js,min.js.gz}`)
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe(gulp.dest(dist.scripts))
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
// copy styles
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.src(`${tmp.styles}/*.{min.css,min.css.gz}`)
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe(gulp.dest(dist.styles))
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
// sourcemaps
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.src(`${tmp.root}/**/*.map`)
|
||||
```suggestion
debug: isDev
```
|
||||
.pipe(gulp.dest(dist.root))
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
done();
|
||||
```suggestion
debug: isDev
```
|
||||
})
|
||||
```suggestion
debug: isDev
```
|
||||
|
||||
```suggestion
debug: isDev
```
|
||||
gulp.task('dist', gulp.series('clean', 'build', 'dist:copy'));
|
||||
```suggestion
debug: isDev
```
|
Loading…
Reference in a new issue