Skip to content

Commit

Permalink
Add support for phases within the next config object
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilwanner committed Apr 27, 2019
1 parent 1b0b8fc commit 6152793
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
});
2 changes: 1 addition & 1 deletion src/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6152793

Please sign in to comment.