Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Add test for Config.toString, add README note
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman committed May 16, 2018
1 parent 0823a1e commit 0107aef
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1196,3 +1196,49 @@ config.toString();
}
*/
```
You can also call `toString` as a static method on `Config` in order to
modify the configuration object prior to stringifying.
```js
const webpackConfig = config.toConfig();

Config.toString({
...config.toConfig(),
module: {
defaultRules: [
{
use: [
{
loader: 'banner-loader',
options: { prefix: 'banner-prefix.txt' },
},
],
},
],
},
})

/*
{
plugins: [
/* config.plugin('foo') */
new TestPlugin()
],
module: {
defaultRules: [
{
use: [
{
loader: 'banner-loader',
options: {
prefix: 'banner-prefix.txt'
}
}
]
}
]
}
}
*/
```
46 changes: 46 additions & 0 deletions test/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,49 @@ test('toString with custom prefix', t => {
`.trim()
);
});

test('static Config.toString', t => {
const config = new Config();

config.plugin('foo').use(class TestPlugin {});

t.is(
Config.toString({
...config.toConfig(),
module: {
defaultRules: [
{
use: [
{
loader: 'banner-loader',
options: { prefix: 'banner-prefix.txt' },
},
],
},
],
},
}).trim(),
`
{
plugins: [
/* config.plugin('foo') */
new TestPlugin()
],
module: {
defaultRules: [
{
use: [
{
loader: 'banner-loader',
options: {
prefix: 'banner-prefix.txt'
}
}
]
}
]
}
}
`.trim()
);
});

0 comments on commit 0107aef

Please sign in to comment.