0

for some reason gulp not creating source maps file for concated and uglified js. I tried different options and setups but with no luck. I was working at one moment but than it stop working. Not sure why.

Here is the gulp task:

'use strict';

var gulp = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
sourcemaps = require('gulp-sourcemaps'),
clean = require('gulp-clean'),
cssmin = require('gulp-cssmin'),
rename = require('gulp-rename'),
runSequence = require('run-sequence'),
concat = require('gulp-concat'),
uglify = require('gulp-uglifyjs');

// Configure sass
gulp.task('sass', () => {
return gulp.src('sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(sourcemaps.write('sourceMap'))
.pipe(gulp.dest('web/css'))
});

// Configure autoprefixer
gulp.task('autoprefixer', () => {
gulp.src(['web/css/**/*.css'])
  .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: false
  }))
  .pipe(gulp.dest('web/css/'))
});

// Configure clean task
gulp.task('clean:css', () => {
gulp.src('web/css/*.css')
.pipe(clean())
});

// Configure css min
var cssMinifyLocation = ['web/css/*.css', '!web/css/*.min.css'];
gulp.task('css:min', () => {
return gulp.src(cssMinifyLocation)
.pipe(autoprefixer())
.pipe(cssmin())
.pipe(rename(
  {suffix: '.min'}
)) 
.pipe(gulp.dest('web/css'))
});

// Configure jsconcat and jsmin

gulp.task('compilejs', function()
{
gulp.src(
[
  'web/js/twigjs/**/*.js'
])
.pipe(sourcemaps.init())
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(rename({
  suffix: '.min'
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('web/js'));
});

// Configure watch
gulp.task('watch', () => {
gulp.watch('sass/**/*.scss', () => { runSequence('clean:css', 'sass', 
'autoprefixer', ['css:min']) });
gulp.watch('web/js/twigjs/**/*.js', () => {runSequence('compilejs')});
});

// Run build task
gulp.task('build', (callback) => {
runSequence('clean:css', 'sass', 'autoprefixer',
['css:min'], callback);
});

Please advise, and provide feedback. Or if you have suggestion what to do in some different way.

youngster
  • 195
  • 1
  • 12
  • hi. Have you checked at which point does it fail? Does it really go through concat and uglify just fine? By the way i'd use gulp.src('web/js/twigjs/**/*.js') - as in omit the square brackets – gabore Nov 28 '18 at 09:57

1 Answers1

0

Try this code:

gulp.task('compilejs', function()
{
  gulp.src(
    [
      'web/js/twigjs/**/*.js'
    ])
    .pipe(sourcemaps.init())
    .pipe(concat('scripts.js'))
    .pipe(uglify())
    .pipe(rename({
      suffix: '.min'
    }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('web/js'));
});
troxxx
  • 51
  • 2
  • Unfortunately it does not work. I have similar set up task for sass, and it generates sourcemaps normally. – youngster Feb 23 '18 at 11:20