Hi there,
Following up on this thread, is it possible to run a gulp task only on gulp --production
?
Since I don’t have SSH access to my remote server, I have to upload my changed files with a gulp task using vinyl-ftp:
// ### Vinyl FTP
gulp.task( 'upload', ['rmdirs'], function ( cb ) {
var conn = ftp.create( ftppass );
var globs = [
'*',
'*.php',
'dist/**',
'lang/**',
'templates/*.php',
'lib/*.php',
'!.ftppass.json',
'!.git',
'!*.json',
'!*.md',
'!*.xml',
'!assets',
'!bower_components',
'!gulpfile.js',
'!node_modules',
'!node_modules/**',
];
// using base = '.' will transfer everything to /public_html correctly
// turn off buffering in gulp.src for best performance
return gulp.src( globs, { base: '.', buffer: false } )
.pipe( conn.newer( '/public_html/web/app/themes/sage/' ) ) // only upload newer files
.pipe( conn.dest( '/public_html/web/app/themes/sage/' ) );
});
// Remove directories
gulp.task( 'rmdirs', ['rmdirScripts', 'rmdirStyles'] );
// Remove dist/scripts directory
gulp.task( 'rmdirScripts', function ( cb ) {
var conn = ftp.create( ftppass );
conn.rmdir( '/public_html/web/app/themes/sage/dist/scripts', cb );
});
// Remove dist/styles directory
gulp.task( 'rmdirStyles', function ( cb ) {
var conn = ftp.create( ftppass );
conn.rmdir( '/public_html/web/app/themes/sage/dist/styles', cb );
});
Since it doesn’t automatically delete older minified production scripts and styles, I have to run a gulp sequence which will delete the dist/scripts and dist/styles directories first remotely before uploading the new ones.
This works perfect, however when running gulp
, the upload
task also runs which causes non-production files to get uploaded and deleting the production files in dist/scripts and dist/styles.
So to completely solve my problem, I have to run the upload task only with the --production
flag.
How do I achieve this?
Thanks!