launchcodedev / app-config

Easy Configuration Loader with Strict Validation
https://app-config.dev
Mozilla Public License 2.0
69 stars 11 forks source link

Usage in NextJS Apps #210

Open mikelfcosta opened 2 years ago

mikelfcosta commented 2 years ago

Hey!

I've used this library really well in SPA apps and express servers, and it worked perfectly with the schema validation and environment configs.

While trying to use it in a NextJS app, I ran into the following issues:

Has anyone had success using this lib with a NextJS app, or if there are any plans for a plugin to support it?

joelgallant commented 2 years ago

Hey thanks! I don't know very much about the NextJS build pipeline. But it sure sounds like a plugin we could build, similar (if not using) to the webpack plugin. You're right that today, the webpack plugin does only work if using the HTML plugin, something that most people do today.

You might be able to use the webpack plugin with headerInjection: false though. I think that's the only option that requires the HTML plugin.

fstylermiller commented 1 year ago

Looking at it, headerInjection: false doesn't quite solve the issue. While it may be the only config option using the plugin, the index file still tries to import from the library. Given that it's a peer dependency of @app-config/webpack it might not be best to assume the package exists in the index file.

Checking to see if the module exists first using require.resolve("html-webpack-plugin") might be a solution.

joelgallant commented 1 year ago

the index file still tries to import from the library

Oh! The import there makes sense, I didn't notice that. So a lazy load instead would likely work.

fstylermiller commented 1 year ago

I'm looking to create a PR to lazy load the module! It doesn't seem that I have access to push to a new branch.

fstylermiller commented 1 year ago

I was able to create a PR for lazy loading: https://github.com/launchcodedev/app-config/pull/218