Injects data-filepath and data-component into JSX elements for source mapping
npm install babel-plugin-source-mapperA Babel plugin to inject data-filepath and data-component attributes into React JSX elements.
This is useful for:
- Mapping DOM elements back to their source files
- Building screen-to-source tools
- Enabling AI agents to reason about code ownership
- This is built by TestChimp primarily for mapping the source files related to screens of webapps during exploratory testing
npm install –save-dev babel-plugin-source-mapper
``js
const sourceMapper = require('babel-plugin-source-mapper');
module.exports = {
babel: {
plugins: [sourceMapper],
},
webpack: {
configure: (config) => {
config.optimization.minimize = false;
return config;
},
},
};
`
Each JSX element will get:
Notes
• Only applies to custom React components (not HTML tags)
• Skips node_modules
• Works best with NODE_ENV=development and minification turned off