UNPKG

@gravityforms/gulp-tasks

Version:
32 lines (26 loc) 1.04 kB
const gulp = require( 'gulp' ); const uglify = require( 'gulp-uglify' ); const rename = require( 'gulp-rename' ); const fs = require( 'fs' ); const getConfig = require( '../../config' ); const { config } = getConfig(); const rootPath = config?.paths?.root || './'; // Check if webpack.config.js exists in the rootPath, this is for legacy addons only const webpackConfigExists = fs.existsSync( `${ rootPath }/webpack.config.js` ); module.exports = Object.assign( {}, { minifyFiles() { if ( webpackConfigExists ) { console.log( 'Skipping minifyFiles task because webpack.config.js is present and it will minify instead in legacy addons.' ); return Promise.resolve(); } return gulp.src( config?.uglify?.minifyFiles || [] ) .pipe( uglify() ) .pipe( rename( function( file ) { file.basename += '.min'; } ) ) .pipe( gulp.dest( function( file ) { // Return the base path of each file to place minified files in the same directory return file.base; } ) ); } }, config?.tasks?.builtins?.uglify || {} );