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

Update API for base config, dev server, and output #38

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ config
.context(context)
.externals(externals)
.loader(loader)
.parallelism(parallelism)
.profile(profile)
.recordsPath(recordsPath)
.recordsInputPath(recordsInputPath)
Expand Down Expand Up @@ -370,15 +371,14 @@ config.entryPoints
config.output : ChainedMap

config.output
.auxiliaryComment(auxiliaryComment)
.chunkFilename(chunkFilename)
.chunkLoadTimeout(chunkLoadTimeout)
.crossOriginLoading(crossOriginLoading)
.filename(filename)
.library(library)
.libraryExport(libraryExport)
.libraryTarget(libraryTarget)
.devtoolFallbackModuleFilenameTemplate(devtoolFallbackModuleFilenameTemplate)
.devtoolLineToLine(devtoolLineToLine)
.devtoolModuleFilenameTemplate(devtoolModuleFilenameTemplate)
.filename(filename)
.hashFunction(hashFunction)
.hashDigest(hashDigest)
.hashDigestLength(hashDigestLength)
Expand All @@ -387,6 +387,9 @@ config.output
.hotUpdateFunction(hotUpdateFunction)
.hotUpdateMainFilename(hotUpdateMainFilename)
.jsonpFunction(jsonpFunction)
.library(library)
.libraryExport(libraryExport)
.libraryTarget(libraryTarget)
.path(path)
.pathinfo(pathinfo)
.publicPath(publicPath)
Expand Down Expand Up @@ -646,13 +649,27 @@ config.node
config.devServer : ChainedMap
```

#### Config devServer allowedHosts

```js
config.devServer.allowedHosts : ChainedSet

config.devServer.allowedHosts
.add(value)
.prepend(value)
.clear()
```

#### Config devServer: shorthand methods

```js
config.devServer
.bonjour(bonjour)
.clientLogLevel(clientLogLevel)
.color(color)
.compress(compress)
.contentBase(contentBase)
.disableHostCheck(disableHostCheck)
.filename(filename)
.headers(headers)
.historyApiFallback(historyApiFallback)
Expand All @@ -661,18 +678,26 @@ config.devServer
.hotOnly(hotOnly)
.https(https)
.inline(inline)
.info(info)
.lazy(lazy)
.noInfo(noInfo)
.open(open)
.openPage(openPage)
.overlay(overlay)
.pfx(pfx)
.pfxPassphrase(pfsPassphrase)
.port(port)
.progress(progress)
.proxy(proxy)
.public(public)
.publicPath(publicPath)
.quiet(quiet)
.setup(setup)
.socket(socket)
.staticOptions(staticOptions)
.stats(stats)
.stdin(stdin)
.useLocalIp(useLocalIp)
.watchContentBase(watchContentBase)
.watchOptions(watchOptions)
```
Expand Down
3 changes: 2 additions & 1 deletion src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = class extends ChainedMap {
'context',
'externals',
'loader',
'parallelism',
'profile',
'recordsPath',
'recordsInputPath',
Expand Down Expand Up @@ -63,7 +64,7 @@ module.exports = class extends ChainedMap {
output: this.output.entries(),
resolve: this.resolve.toConfig(),
resolveLoader: this.resolveLoader.toConfig(),
devServer: this.devServer.entries(),
devServer: this.devServer.toConfig(),
module: this.module.toConfig(),
plugins: this.plugins.values().map(plugin => plugin.toConfig()),
performance: this.performance.entries(),
Expand Down
48 changes: 47 additions & 1 deletion src/DevServer.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,80 @@
const ChainedMap = require('./ChainedMap');
const ChainedSet = require('./ChainedSet');
const merge = require('deepmerge');

module.exports = class extends ChainedMap {
constructor(parent) {
super(parent);

this.allowedHosts = new ChainedSet(this);

this.extend([
'bonjour',
'clientLogLevel',
'color',
'compress',
'contentBase',
'disableHostCheck',
'filename',
'headers',
'historyApiFallback',
'host',
'hot',
'hotOnly',
'https',
'info',
'inline',
'lazy',
'noInfo',
'open',
'openPage',
'overlay',
'pfx',
'pfxPassphrase',
'port',
'proxy',
'progress',
'public',
'publicPath',
'proxy',
'quiet',
'setup',
'socket',
'staticOptions',
'stats',
'stdin',
'useLocalIp',
'watchContentBase',
'watchOptions'
]);
}

toConfig() {
return this.clean(Object.assign({
allowedHosts: this.allowedHosts.values(),
}, this.entries() || {}));
}

merge(obj) {
Object
.keys(obj)
.forEach(key => {
const value = obj[key];

switch (key) {
case 'allowedHosts': {
return this[key].merge(value);
}

default: {
if (this.has(key)) {
this.set(key, merge(this.get(key), value));
} else {
this.set(key, value);
}
}
}
});

return this;
}
};
12 changes: 7 additions & 5 deletions src/Output.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ module.exports = class extends ChainedMap {
constructor(parent) {
super(parent);
this.extend([
'auxiliaryComment',
'chunkFilename',
'chunkLoadTimeout',
'crossOriginLoading',
'filename',
'library',
'libraryExport',
'libraryTarget',
'devtoolFallbackModuleFilenameTemplate',
'devtoolLineToLine',
'devtoolModuleFilenameTemplate',
'hashFunction',
'filename',
'hashDigest',
'hashDigestLength',
'hashFunction',
'hashSalt',
'hotUpdateChunkFilename',
'hotUpdateFunction',
'hotUpdateMainFilename',
'jsonpFunction',
'library',
'libraryExport',
'libraryTarget',
'path',
'pathinfo',
'publicPath',
Expand Down
8 changes: 8 additions & 0 deletions test/DevServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ test('is Chainable', t => {
t.is(devServer.end(), parent);
});

test('sets allowed hosts', t => {
const devServer = new DevServer();
const instance = devServer.allowedHosts.add('https://github.com').end();

t.is(instance, devServer);
t.deepEqual(devServer.toConfig(), { allowedHosts: ['https://github.com'] });
});

test('shorthand methods', t => {
const devServer = new DevServer();
const obj = {};
Expand Down
1 change: 1 addition & 0 deletions test/ResolveLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test('sets methods', t => {
const instance = resolveLoader.modules.add('src').end();

t.is(instance, resolveLoader);
t.deepEqual(resolveLoader.toConfig(), { modules: ['src'] });
});

test('toConfig empty', t => {
Expand Down