markshapiro / webpack-merge-and-include-globally

Merge multiple files (js, css..) and include by running them "as is". Supports minify by custom transform and wildcard paths.
MIT License
102 stars 27 forks source link

Add ability to generate maps for merged files #65

Open Dvvarf opened 3 years ago

Dvvarf commented 3 years ago

As stated in title, this patch adds ability to generate maps for merged files. Not after concatenation, but before. Turns out there is even an issue that could be fixed by this PR: #35.

How to use:

  1. Add sourceMap property to MergeIntoFile constructor's options. sourceMap can be a boolean or object with these properties, both optional: sourceRoot (string - root path to map merged files against), inlineSources (boolean - set to true to include source files into map files).
  2. Use callback in files array that should look like this in the simplest case:
    (code, map) => ({
    "file.js": code,
    "file.js.map": map.toString(),
    })

In this callback map is an instance of SourceMapGenerator. It can be passed further to Terser or processed in any other way you'd like.