Expose function for config resolving #40891
RyanClementsHax
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
Although not documented, I believe Next.js does export a function to load config. Here is an example of its usage: const loadConfig = require('next/dist/server/config').default;
// function loadConfig(
// phase: string,
// dir: string,
// customConfig?: object | null
// ): Promise<NextConfigComplete>
const { PHASE_PRODUCTION_BUILD } = require('next/constants');
const nextConfig = await loadConfig(PHASE_PRODUCTION_BUILD, process.cwd());
See also the source code of |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the feature you'd like to request
Current behavior:
There is no official or clean way to resolve the nextjs config without any side effects
Desired behavior:
Expose a function that resolves the nextjs config and applies all of the defaults and other logic
Use case:
As the developer of storybook-addon-next, an addon that aims to make nextjs work seamlessly with storybook, I'm finding it really hard to support all of the features of
next/image
well. Many users want to be able to use loaders and other features that require the next config to be resolved. I could replicate this myself, but the logic to resolve the config and apply the defaults changes between versions frequently thus making this method very brittle to nextjs updates.Describe the solution you'd like
Something of the following sort that allows me to resolve the final nextjs config within a user's repo.
Perhaps:
It could also accept parameters to help resolve the config like a file path to the config or the raw nextjs config itself
Describe alternatives you've considered
I have tried writing the logic manually, but this is brittle. This work is shown here.
Beta Was this translation helpful? Give feedback.
All reactions