I'm using gulp to build project, together with gulp-sourcemaps for generating sourcemaps.
I have several compnents like this:
public
|-- src
|-- comp1
| |-- c1-a.js
| |-- c1-b.js
|
|-- comp2
|-- c2-a.js
|-- c2-b.js
I'd like to build them into following strcture:
public
|-- dist
| |-- comp1
| | |-- c1-a.min.js
| | |-- c1-a.min.js.map
| | |-- c1-b.min.js
| | |-- c1-b.min.js.map
| |
| |-- comp2
| |-- c2-a.min.js
| |-- c2-a.min.js.map
| |-- c2-b.min.js
| |-- c2-a.min.js.map
|
|-- src/
Currently my gulp task can generate files into correct path:
gulp.task('component', function() {
gulp.src('./public/src/**/*.js', {base: './public/src'})
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.', {
includeContent: false,
sourceRoot: '/src/' // here's the problem
}))
.pipe(gulp.dest('./public/dist'))
})
but there are two problems:
the
sourceRoot
in map file is not correct: expecting"sourceRoot":"/src/comp1/"
but the result is"sourceRoot":"/src/"
neither does
sourceMappingURL
in compressed file: expectingsourceMappingURL=c1-a.min.js.map
but the result issourceMappingURL=../../comp1/c1-a.min.js.map
How can I append the **
part to sourceRoot
and fix sourceMappingURL?