MCPcopy Index your code
hub / github.com/caiogondim/webpack-conditional-loader

github.com/caiogondim/webpack-conditional-loader @v1.0.11

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.11 ↗ · + Follow
5 symbols 10 edges 7 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

webpack-conditional-loader

Inspired by C conditionals directive, conditional loader decides if a given block should be included in the final bundle.

Useful for removing instrumentation code and making your final production bundle smaller (therefore faster).

Installation

npm install --save-dev webpack-conditional-loader

Usage

In your webpack.config.js

Put webpack-conditional-loader as the last loader in the array, so it will process the code before all others.

module: {
  rules: [{
    test: /\.js$/,
    use: ['babel-loader', 'webpack-conditional-loader']
  }]
}

Get an example config file here

On your code

Use // #if expression and // #endif to wrap blocks of code you want to be removed if a given predicate is false.

// #if process.env.NODE_ENV === 'DEVELOPMENT'
console.log('lorem')
console.log('ipsum')
// #endif

In the example above, the code will be removed if the enviroment variable NODE_ENV is not DEVELOPMENT, removing unnecessary code from your production bundle.

The same technique can be used to prevent loading packages in the production bundle.

// #if process.env.NODE_ENV !== 'BUILD'
import reduxLogger from 'redux-logger'
// #endif

Credits


caiogondim.com  ·  GitHub @caiogondim  ·  Twitter @caio_gondim

Core symbols most depended-on inside this repo

getPredicate
called by 1
src/index.js
searchBlocks
called by 1
src/index.js
getTruthyBlocks
called by 1
src/index.js
commentCodeInsideBlocks
called by 1
src/index.js
commentLine
called by 1
src/index.js

Shape

Function 5

Languages

TypeScript100%

Modules by API surface

src/index.js5 symbols

For agents

$ claude mcp add webpack-conditional-loader \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact