An open API service indexing awesome lists of open source software.

https://github.com/revan-zhang/placeholder-loader

pipe the raw content to next loader in webpack
https://github.com/revan-zhang/placeholder-loader

loader webpack webpack-loader

Last synced: about 2 months ago
JSON representation

pipe the raw content to next loader in webpack

Awesome Lists containing this project

README

          

# placeholder-loader
always return the same source code when pass to the placeholder-loader

why we need this?
bacause in webpack must pass a non-string in loader array, like:

```js
{
test: /\.js$/,
use: [
'babel-loader',
'ts-loader',
]
}
```

but sometime, we want to use different loader in different env, like:

```js
{
test: /\.js$/,
use: [
'babel-loader',
process.env.NODE_ENV === 'production' ? 'awesome-typescript-loader' : 'ts-loader'
]
}
```

the placeholder loader is to solve some config like this:

```js
{
test: /\.js$/,
use: [
'babel-loader',
process.env.NODE_ENV === 'SERVER_RENDERING' ? '' : 'promise-loader'
]
}
```

in the config above, we don't use promise-loader when the SERVER_RENDERING is true,
but webpack doesn't allow empty string, we must write something at there.
so, we can write the path to placeholder-loader, it will pipe the code to next loader.