-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exclude node_modules from source map #1685
Comments
Here is a plugin that does what #1227 does but for anything with let plugin = {
name: 'excludeVendorFromSourceMap',
setup(build) {
build.onLoad({ filter: /node_modules/ }, args => {
return {
contents: fs.readFileSync(args.path, 'utf8')
+ '\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
loader: 'default',
}
})
},
} Feel free to customize the plugin further for your needs. You can read more about esbuild plugins here: https://esbuild.github.io/plugins/. |
Thanks, I have modified it to work only on const excludeVendorFromSourceMapPlugin = ({ filter }) => ({
name: 'excludeVendorFromSourceMap',
setup(build) {
build.onLoad({ filter }, (args) => {
if (args.path.endsWith('.js')) {
return {
contents:
readFileSync(args.path, 'utf8') +
'\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==',
loader: 'default',
};
}
});
},
}); If you don't want to add this to |
Yes, I think this makes sense to do as a plugin instead of as part of esbuild's API. Closing. |
I came here from this comment. After enabling the Using your plugin to make the source map file smaller did the trick to lower memory usage to expected levels 👍 The file went from 9.8mb to 493.1kb. Thank you. Modified pluginconst excludeVendorFromSourceMapPlugin = {
name: 'excludeVendorFromSourceMapPlugin',
setup(build) {
const emptySourceMapAsBase64 = Buffer.from(JSON.stringify({ version: 3, sources: [''], mappings: 'A' })).toString(
'base64'
);
build.onLoad({ filter: /node_modules.+\.(js|ts)$/ }, (args) => {
return {
contents: `${fs.readFileSync(args.path, 'utf8')}\n//# sourceMappingURL=data:application/json;base64,${emptySourceMapAsBase64}`,
loader: 'default'
};
});
}
}; |
Is there a way to exclude a folder from source maps while keeping files in bundle.
Similar issues
node_modules
folder instead of a single file.Background:
My source maps are too big even with
sourcesContent: false
(I only need stack-traces). Big source maps take some time to load withnode --enable-source-maps
The text was updated successfully, but these errors were encountered: