mike-lischke / antlr4ng

Next Generation TypeScript runtime for ANTLR4
Other
66 stars 11 forks source link

Generate sourcemaps #35

Closed nashbridges closed 4 months ago

nashbridges commented 4 months ago

Somehow generated cjs/mjs bundles contain

//# sourceMappingURL=index.mjs.map

line, whereas the actual sourcemap file is not included.

When using CRA (Webpack), this results in the following warning (see https://github.com/facebook/create-react-app/pull/11752)

WARNING in ./node_modules/antlr4ng/dist/index.mjs Module Warning (from ./node_modules/source-map-loader/dist/cjs.js): Failed to parse source map from '/Users/nash/projects/my-project/node_modules/antlr4ng/dist/index.mjs.map' file: Error: ENOENT: no such file or directory, open '/Users/nash/projects/my-project/node_modules/antlr4ng/dist/index.mjs.map'

To fix that we have either to make sure the hint line is not there, or actually generate sourcemaps. I think latter is more useful.

nashbridges commented 4 months ago

The downside is that the package size will increase. The resulting map is about 900Kb (200Kb zipped), and it is duplicated both for .cjs and .mjs.

mike-lischke commented 4 months ago

Including the full maps is not a good idea, sorry. Since you never debug the package in your target project and you don't have the package sources at hand to which the mappings point, it simply makes no sense to include those.

The source map reference line is a left over from the build process, where I generated the maps and excluded them from bundling, but didn't think about that reference line.

So, the best approach is not to generate source maps at all, at least not for packaging.

nashbridges commented 4 months ago

The source map reference line is a left over from the build process, where I generated the maps and excluded them from bundling, but didn't think about that reference line.

Ah, I see. So the next release won't have the hint, right?

mike-lischke commented 4 months ago

Yep, that's the plan.