diff --git a/README.md b/README.md index 1135374..d0d9abb 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,17 @@ module.exports = withPlugins([ ], nextConfig); ``` +Phases are also supported within the `nextConfiguration` object and have the same syntax as in [plugin `configuration` objects](#configuration-object). +```javascript +const { PHASE_DEVELOPMENT_SERVER } = require('next-server/constants'); +const nextConfig = { + distDir: 'build', + ['!' + PHASE_DEVELOPMENT_SERVER]: { + assetPrefix: 'https://my.cdn.com', + }, +}; +``` + ### Optional plugins If a plugin should only get loaded when it is used, you can use the `optional` helper function. diff --git a/src/__tests__/index.test.js b/src/__tests__/index.test.js index c504928..d9ba192 100644 --- a/src/__tests__/index.test.js +++ b/src/__tests__/index.test.js @@ -101,4 +101,28 @@ describe('next-compose-plugins', () => { expect(plugin1).toHaveBeenCalledTimes(1); expect(plugin2).toHaveBeenCalledTimes(1); }); + + it('resolves phases specific configs in the next configuration', () => { + const baseConfig = withPlugins([], { + baseConfig: 'hello', + foo: 'bar', + [PHASE_DEVELOPMENT_SERVER]: { + foo: 'baz', + }, + [`!${PHASE_PRODUCTION_SERVER}`]: { + prod: false, + }, + [`!${PHASE_DEVELOPMENT_SERVER}`]: { + dev: false, + }, + }); + + const result = baseConfig(PHASE_DEVELOPMENT_SERVER, {}); + + expect(result).toEqual({ + baseConfig: 'hello', + foo: 'baz', + prod: false, + }); + }); }); diff --git a/src/compose.js b/src/compose.js index 56147c6..ac81ea0 100644 --- a/src/compose.js +++ b/src/compose.js @@ -58,7 +58,7 @@ export const composePlugins = (phase, plugins, initialConfig) => { nextComposePlugins: true, phase, }; - let config = { ...initialConfig }; + let config = mergePhaseConfiguration(phase, { ...initialConfig }); plugins.forEach((plugin) => { const { pluginFunction, pluginConfig, phases } = parsePluginConfig(plugin);