denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.05k stars 607 forks source link

Configuration-Driven Running Modes/Profiles #2531

Closed x80486 closed 1 week ago

x80486 commented 1 week ago

Description

Currently, when Fresh project is generated, a dev.ts and main.ts files are created — along with some related tasks. These files are intuitive enough to figure it out what's their role within the project.

The dev.ts file looks very much like something users shouldn't have to deal with directly because it reflects a way to run the application. I think this approach could be streamlined because Fresh already has a configuration file. Basically, Fresh could be able to hide all this and have a single entrypoint by introducing the notion of running modes (or something similar), driven by the configuration file and some flag specified in a task when the application is run.

This could lead to a more declarative configuration, where things like dotenv (usually only used for local development) and things like that are meant to be used only, let's say in dev mode, and some others won't be used in prod or test mode — just throwing ideas.

// fresh.config.js
export default defineConfig({
  modes: {
    dev: {
      loadModules: ["dotenv"],
      envFile: ".env"
      watch: ["components", "routes", "static"]
    }
    prod: {
      // ...
    },
    test {
      loadModules: ["dotenv"]
      envFile: ".env"
    }
  }
});

I'm not sure how complex this could be, or if it aligns with how you would like Fresh to behave in general, but it certainly reduces boilerplate code (for users) and makes environment management more intuitive — twelve-factor app, etc.

marvinhagemeister commented 1 week ago

You might be happy to hear that this has been cleaned up a bit with the upcoming Fresh 2 release. The code has already landed in the main branch and can be checked out. We got rid of the config file all together and moved everything dev related into dev.ts and anything else into main.ts.

x80486 commented 1 week ago

Looking forward Fresh 2.0 release! :ok_hand: