babel-plugin-dev-strip
v1.0.1
Published
A Babel plugin that strips code blocks marked with @dev-only comment directive from production builds.
Maintainers
Readme
babel-plugin-dev-strip
A Babel plugin that strips code blocks marked with a @dev-only comment directive from production builds.
Installation
npm install babel-plugin-dev-strip --save-devUsage
Add the plugin to your Babel configuration:
{
"plugins": ["babel-plugin-dev-strip"]
}Then mark any code you want to remove in production with // @dev-only:
// @dev-only
console.log('debug info:', data);
// @dev-only
if (window.__DEBUG__) {
renderDebugOverlay();
trackRenderCount(Component);
}
doSomething(); // this staysAfter transformation:
doSomething();Supported Patterns
Statements (if, expressions, variable declarations, function declarations)
// @dev-only
const debugInfo = computeDebugInfo();
// @dev-only
function debugHelper() {
return 'debug';
}Class methods and properties
class App {
// @dev-only
debugMode = true;
// @dev-only
debugMethod() {
console.log('debug');
}
}Object properties and methods
const config = {
// @dev-only
debug: true,
production: true,
};Block comments
/* @dev-only */
console.log('this also works');Options
directive
Type: string
Default: '@dev-only'
Customize the comment directive to match.
{
"plugins": [["babel-plugin-dev-strip", { "directive": "@test-only" }]]
}// @test-only
setupMocks();License
MIT
