https://github.com/benignware/merge-loader
A webpack loader to merge modules
https://github.com/benignware/merge-loader
Last synced: 2 days ago
JSON representation
A webpack loader to merge modules
- Host: GitHub
- URL: https://github.com/benignware/merge-loader
- Owner: benignware
- Created: 2017-08-26T19:31:47.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-04T17:35:20.000Z (almost 9 years ago)
- Last Synced: 2025-09-16T23:49:42.197Z (9 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# merge-loader
> A webpack loader to merge modules
## Installation
```cli
npm i merge-loader
```
## Usage
### Example
webpack.config.js
```js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
module: {
rules: [
{
test: /config.js$/,
use: [
{
loader: 'merge-loader',
options: {
pattern: [
`env/${process.env.NODE_ENV}/config.*`
]
}
}
]
}
]
}
};
```
src/config.js
```js
module.exports = {
helloWorld: 'Hello World'
};
```
src/env/production/config.js
```js
module.exports = {
environment: function() {
return 'Production';
}
};
```
src/index.js
```js
const { helloWorld, environment } = require('./config.js');
console.log(helloWorld); // Hello World
console.log(environment()); // Production
```
> The example assumes that `process.env.NODE_ENV` is set to `production`. This can be achieved with [cross-env](https://www.npmjs.com/package/cross-env) when issued as a shell command:
```cli
cross-env NODE_ENV=production webpack
```
## Options
| Param | Type | Description |
| -------- | -------------------------------- | -------------------------------- |
| pattern | string|array | Provide one or more glob patterns to match files that should be merged in. See [glob](https://www.npmjs.com/package/glob) for more info.
| glob | object | Options passed to [glob](https://www.npmjs.com/package/glob).
| merge | string | Specify a module used for merging. Defaults to merge-loader's own implementation at [./lib/merge](./lib/merge.js)`.