Chris Katz
Chris Katz

Reputation: 31

Gulp - Using existing minified files and source maps in combination with non-minified files and source maps

We are using a gulp process that, like most people, compress, uglify, and concat JavaScript files to a single "app.js" file. Some of the files that we are using are distributed via bower and already come pre-minified with source maps. Ideally, instead of re-minifying these files, we just use the .min and .min.map directly. How do we accommodate this?

So, essentially, our JavaScript .src files look like this

'[FILE(S) TO BE UGLIFIED]',
'[FILE(S) ALREADY UGLIFIED]', // these also have map files
'[FILE(S) TO BE UGLIFIED]'

and we want them to all be in one app.min.js and app.min.js.map.

Being these are all copied to a dist directory, its acceptable if we do something like uglify the first set of files, pipe to dist. Take the existing files already uglified + the output from the first batch and concat them (and re-run through sourcemaps) & pipe to dist again, then do the same for the last set.

The gulp plugins that we are already using to do all this are:

"gulp-concat": "2.4.1",
"gulp-uglify": "1.0.1",
"gulp-token-replace": "1.0.1",
"gulp-autoprefixer": "1.0.1",
"gulp-if": "1.2.5",
"gulp-sourcemaps": "1.2.2"

Upvotes: 3

Views: 627

Answers (1)

Frizi
Frizi

Reputation: 2940

gulp sourcemaps plugin allows you to do exactly that very easily. Pipe its sourcemaps.init function just after gulp.src with options {loadMaps: true} and it will check for existing sourcemaps with the same filename, but .map extension at the end.

Upvotes: 1

Related Questions