Webpack loader for toggling javascript comment, avoiding hard code debug snippets in source code files.
npm i comment-toggle-loader -D
{
test: /\.js$/i,
loader: 'comment-toggle-loader',
query: {
enable: process.env.NODE_ENV === 'development'
}
}
Webpack will replace
/* @debug@
console.info('Your debug info here');
*/
with
console.info('Your debug info here');
It will remove comment with query.match
in development
environment and do nothing in production
environment.
Meanwhile, the other comments not contain query.match
will not be toggled.
query.match
: Comments withquery.match
will be toggled. Default is'@[\\w-]+@'
, which is a part of regular expression.query.enable
: Whether or not to enable comment toggling.