Rich-Harris / butternut

The fast, future-friendly minifier
https://butternut.now.sh
MIT License
1.17k stars 17 forks source link

Feature: accept a source map object that the output source map will be based on #73

Open ramasilveyra opened 7 years ago

ramasilveyra commented 7 years ago

Hello! Great work with butternut!

I was trying to add sourcemaps support to butternut-webpack-plugin (https://github.com/Apercu/butternut-webpack-plugin/pull/2) but I dont know how to pass a sourcemap.

Maybe something like what babel does will be good:

babel.transform(input, {
  inputSourceMap
})

https://babeljs.io/docs/usage/api/#babel-transform-code-string-options-object- https://babeljs.io/docs/usage/api/#options

Also Im not sure if this is the right place for this request, maybe it should be in https://github.com/Rich-Harris/magic-string ?

Rich-Harris commented 7 years ago

In general I feel that tools should not know anything about prior transformations — it means that every single step in a build pipeline has to reimplement the same logic, and insodoing significantly increases surface area for bugs.

For example, Rollup will compose sourcemaps from multiple chained transformer plugins without those plugins having to know anything about each other. Each plugin just describes the transformations it implements. I'd assumed that webpack would do something similar (cc @TheLarkInn!)

See also sorcery, which combines sourcemaps from multiple transformations.