gulp-wp-block/gulpfile.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-06-29 20:23:42 +00:00
const { src, dest, series, parallel, watch } = require('gulp');
const argv = require('minimist')(process.argv.slice(2));
const babel = require('gulp-babel');
const terser = require('gulp-terser');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const postcssPresetEnv = require('postcss-preset-env');
const cssnano = require('cssnano');
const babelConfig = require('./babel.config.js');
const postcssPlugins = [postcssPresetEnv(), cssnano()];
const isProduction = argv.build ? argv.build : false;
const buildDir = './dist/';
const jsSrc = './index.jsx';
const jsDest = buildDir;
const scssSrc = './*.scss';
const cssDest = buildDir;
function jsTranspile() {
return src(jsSrc, { sourcemaps: !isProduction })
.pipe(babel(babelConfig))
.pipe(terser())
.pipe(dest(jsDest, { sourcemaps: !isProduction }));
}
function scssCompile() {
return src(scssSrc, { sourcemaps: !isProduction })
.pipe(sass().on('error', sass.logError))
.pipe(postcss(postcssPlugins))
.pipe(dest(cssDest, { sourcemaps: !isProduction }));
}
const jsWatch = () =>
watch(jsSrc, { ignoreInitial: false }, jsTranspile);
const scssWatch = () =>
watch(scssSrc, { ignoreInitial: false }, scssCompile);
exports.default = parallel(
jsWatch,
scssWatch,
);