shama / webpack-stream

:tropical_drink: Run webpack through a stream interface
MIT License
1.4k stars 123 forks source link

Remove the need to manually filter out source map files #246

Open marekdedic opened 2 years ago

marekdedic commented 2 years ago

Hi, I would like to open this feature request to ask to remove the need to manually get rid of sourcemaps when using with gulp-sourcemaps - it seems to me that if I'm using non-inlined sourcemaps, I would almost never want them to be treated as a separate file as opposed to piping them to gulp-sourcemaps.

I'm willing to submit a PR if the issue is discussed and a we agree on a solution.

shama commented 2 years ago

Isn't that handled by the webpack option devtool? https://webpack.js.org/configuration/devtool/

I'm not sure why this library would need to do extra handling of source maps.

marekdedic commented 2 years ago

Hmm, maybe I didn't explain myself clearly - I'm talking about the need to do

.pipe(through.obj(function (file, enc, cb) {
      // Dont pipe through any source map files as it will be handled
      // by gulp-sourcemaps
      const isSourceMap = /\.map$/.test(file.path);
      if (!isSourceMap) this.push(file);
      cb();
}))

Webpack doesn't catre about streams - it just spits out the sourcemap. However, afaik, in gulp-sourcemaps, the sourcemap isn't actually a separate file, so the extra file needs to be removed by the code above.

shama commented 2 years ago

This library doesn't do anything with source maps though so I'm not sure why it would need to have this special circumstance. I think you could just configure webpack to output or not output the desired source maps or just keep doing that code above. I think that use case is outside the scope of this library.

marekdedic commented 2 years ago

Hi, I think the use case is in scope - ultimately, the decision is of course yours, but I will try to change your mind by laying out my thought process:

I do want to produce sourcemaps. I'm using webpack-stream, a library that adapts webpack to a streaming interface (my understanding of its purpose, correct me if I'm wrong). From what I can gather, the standard way of handling source maps in gulp/streams is with the file.sourceMap property on the stream. I am trying to argue that webpack-stream should therefore adapt the webpack output to this format by default (althought changing the default now would be problematic, so let's not do that). As far as I understand this, that is not currently the case - I can either inline the sourcemap into the file itself by setting devtool: "inline-source-map" or have it as a separate file altogether.