Skip to content

Commit 6152793

Browse files
committed
Add support for phases within the next config object
1 parent 1b0b8fc commit 6152793

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ module.exports = withPlugins([
153153
], nextConfig);
154154
```
155155

156+
Phases are also supported within the `nextConfiguration` object and have the same syntax as in [plugin `configuration` objects](#configuration-object).
157+
```javascript
158+
const { PHASE_DEVELOPMENT_SERVER } = require('next-server/constants');
159+
const nextConfig = {
160+
distDir: 'build',
161+
['!' + PHASE_DEVELOPMENT_SERVER]: {
162+
assetPrefix: 'https://my.cdn.com',
163+
},
164+
};
165+
```
166+
156167
### Optional plugins
157168

158169
If a plugin should only get loaded when it is used, you can use the `optional` helper function.

src/__tests__/index.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,28 @@ describe('next-compose-plugins', () => {
101101
expect(plugin1).toHaveBeenCalledTimes(1);
102102
expect(plugin2).toHaveBeenCalledTimes(1);
103103
});
104+
105+
it('resolves phases specific configs in the next configuration', () => {
106+
const baseConfig = withPlugins([], {
107+
baseConfig: 'hello',
108+
foo: 'bar',
109+
[PHASE_DEVELOPMENT_SERVER]: {
110+
foo: 'baz',
111+
},
112+
[`!${PHASE_PRODUCTION_SERVER}`]: {
113+
prod: false,
114+
},
115+
[`!${PHASE_DEVELOPMENT_SERVER}`]: {
116+
dev: false,
117+
},
118+
});
119+
120+
const result = baseConfig(PHASE_DEVELOPMENT_SERVER, {});
121+
122+
expect(result).toEqual({
123+
baseConfig: 'hello',
124+
foo: 'baz',
125+
prod: false,
126+
});
127+
});
104128
});

src/compose.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const composePlugins = (phase, plugins, initialConfig) => {
5858
nextComposePlugins: true,
5959
phase,
6060
};
61-
let config = { ...initialConfig };
61+
let config = mergePhaseConfiguration(phase, { ...initialConfig });
6262

6363
plugins.forEach((plugin) => {
6464
const { pluginFunction, pluginConfig, phases } = parsePluginConfig(plugin);

0 commit comments

Comments
 (0)