UNPKG

@gravityforms/gulp-tasks

Version:
35 lines (28 loc) 1.14 kB
import fs from 'node:fs'; import { createRequire } from 'node:module'; import getConfig from '../../config.js'; const cjsRequire = createRequire( import.meta.url ); const gulp = cjsRequire( 'gulp' ); const uglify = cjsRequire( 'gulp-uglify' ); const rename = cjsRequire( 'gulp-rename' ); 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` ); export default 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 || {} );