Skip to content

Any way to use sourcemaps and minification of files? #99

@davidrhoderick

Description

@davidrhoderick

Looks like as per issues #9 and #49, sourcemaps work if there is no minification. That's great and all but sourcemaps are way more useful when minification is happening and I can see very few use-cases where minification isn't used in production deployment. However, I've tried gulp-uglify and gulp-minify with gulp-sourcemaps and gulp-include and can only get the sourcemaps to work when I skip minification. Here's my current environment:

{
  "dependencies": {
    "browser-sync": "^2.26.3",
    "gulp": "^3.9.1",
    "gulp-include": "^2.3.1",
    "gulp-jshint": "^2.1.0",
    "gulp-minify": "^3.1.0",
    "gulp-notify": "^3.2.0",
    "gulp-plumber": "^1.2.0",
    "gulp-sass": "^4.0.1",
    "gulp-sass-lint": "^1.4.0",
    "gulp-sourcemaps": "^2.6.5",
    "jshint": "^2.9.6",
    "gulp-uglify": "^3.0.2"
  }
}

And I'm on Node 11.15.0. My task looks like the following:

gulp.task('js', function(){
  return gulp.src('static/js/site.js')
    .pipe(sourcemaps.init())
    .pipe(include())
      .on('error', notify)
    .pipe(jshint.reporter('default'))
    .pipe(minify({
      noSource: true,
      ext:{
        src: '.js',
        min: '.min.js'
      }
    }))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('static'))
    .pipe(browserSync.stream());
});

That's with gulp-minify, which I'd ideally like to use, but even when I remove that .pipe(minify({...}) block and put in .pipe(uglify()), I still don't get a proper sourcemap. I can see that it's trying because it says that my test file, which is at the end of including jQuery, is part of jQuery only at the end of the file. If I even just include the site.js instead of site.min.js, it's correct. Does anyone have a working method for using sourcemaps with include and minification?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions