🧹 clean up build process
This commit is contained in:
109
gulpfile.js
109
gulpfile.js
@@ -1,131 +1,54 @@
|
||||
const { src, dest, parallel, series, watch } = require('gulp');
|
||||
const csslint = require('gulp-csslint');
|
||||
const autoprefixer = require('gulp-autoprefixer');
|
||||
const minify = require('gulp-minify');
|
||||
const cleanCss = require('gulp-clean-css');
|
||||
const rename = require('gulp-rename');
|
||||
const header = require('gulp-header');
|
||||
const eslint = require('gulp-eslint');
|
||||
const fs = require('fs-extra');
|
||||
const htmlMin = require('gulp-htmlmin');
|
||||
const browserify = require('browserify');
|
||||
const source = require('vinyl-source-stream');
|
||||
const buffer = require('vinyl-buffer');
|
||||
const sass = require('gulp-sass');
|
||||
|
||||
var packageJson = null;
|
||||
var banner = [
|
||||
'/**',
|
||||
' * <%= pkg.name %> - <%= pkg.description %>',
|
||||
' * @version v<%= pkg.version %>',
|
||||
' * @link <%= pkg.homepage %>',
|
||||
' * @author <%= pkg.author.name %> - <%= pkg.author.url %>',
|
||||
' * @license <%= pkg.license %>',
|
||||
' */',
|
||||
''
|
||||
].join('\n');
|
||||
|
||||
/**
|
||||
* Process HTML files.
|
||||
*/
|
||||
function html() {
|
||||
return src('./src/html/component.html')
|
||||
.pipe(htmlMin({ collapseWhitespace: true }))
|
||||
.pipe(rename('./src/html/component-min.html'))
|
||||
.pipe(dest('./'));
|
||||
return src('./src/html/component.html')
|
||||
.pipe(htmlMin({ collapseWhitespace: true }))
|
||||
.pipe(rename('./src/html/component-min.html'))
|
||||
.pipe(dest('./'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process CSS file.
|
||||
*/
|
||||
function css() {
|
||||
return src('./src/scss/component.scss')
|
||||
.pipe(sass())
|
||||
.pipe(csslint())
|
||||
.pipe(csslint.formatter())
|
||||
.pipe(
|
||||
autoprefixer({
|
||||
browsers: ['last 2 versions'],
|
||||
cascade: false
|
||||
})
|
||||
)
|
||||
.pipe(cleanCss())
|
||||
.pipe(rename('./src/css/component-min.css'))
|
||||
.pipe(dest('./'));
|
||||
return src('./src/scss/component.scss')
|
||||
.pipe(sass())
|
||||
.pipe(autoprefixer())
|
||||
.pipe(cleanCss())
|
||||
.pipe(rename('./src/css/component-min.css'))
|
||||
.pipe(dest('./'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the JavaScript library file.
|
||||
*/
|
||||
function js() {
|
||||
packageJson = fs.readJsonSync('./package.json');
|
||||
packageJson = fs.readJsonSync('./package.json');
|
||||
|
||||
return src('./src/js/mailymaily.js')
|
||||
.pipe(eslint())
|
||||
.pipe(eslint.format())
|
||||
.pipe(minify({ noSource: true }))
|
||||
.pipe(header(banner, { pkg: packageJson }))
|
||||
.pipe(dest('dist'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lint JavaScript file used on demo page.
|
||||
*/
|
||||
function lintDemoJs() {
|
||||
return src('./demo/demo.js')
|
||||
.pipe(eslint())
|
||||
.pipe(eslint.format());
|
||||
}
|
||||
|
||||
/**
|
||||
* Process JavaScript file used on demo page.
|
||||
*/
|
||||
function processDemoJs() {
|
||||
return browserify('./demo/demo.js')
|
||||
.bundle()
|
||||
.pipe(source('./demo/demo.js'))
|
||||
.pipe(buffer())
|
||||
.pipe(minify({ noSource: true }))
|
||||
.pipe(dest('./'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process CSS file used on demo page.
|
||||
*/
|
||||
function demoCss() {
|
||||
return src('./demo/demo.scss')
|
||||
.pipe(sass())
|
||||
.pipe(csslint())
|
||||
.pipe(csslint.formatter())
|
||||
.pipe(
|
||||
autoprefixer({
|
||||
browsers: ['last 2 versions'],
|
||||
cascade: false
|
||||
})
|
||||
)
|
||||
.pipe(cleanCss())
|
||||
.pipe(rename('./demo/demo-min.css'))
|
||||
.pipe(dest('./'));
|
||||
return src('./src/js/mailymaily.js').pipe(minify({ noSource: true })).pipe(dest('dist'));
|
||||
}
|
||||
|
||||
/**
|
||||
* The all seeing eye...
|
||||
*/
|
||||
function watchFiles() {
|
||||
watch('./src/html/component.html', html);
|
||||
watch('./src/scss/component.scss', css);
|
||||
watch(['./src/js/mailymaily.js', './package.json']);
|
||||
watch('./src/html/component.html', html);
|
||||
watch('./src/scss/component.scss', css);
|
||||
watch([ './src/js/mailymaily.js', './package.json' ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define complex tasks.
|
||||
*/
|
||||
const build = series(parallel(html, css), js);
|
||||
const watching = series(build, watchFiles);
|
||||
|
||||
/**
|
||||
* Make tasks available to the outside world.
|
||||
*/
|
||||
//-----
|
||||
exports.html = html;
|
||||
exports.css = css;
|
||||
exports.js = js;
|
||||
|
||||
Reference in New Issue
Block a user