Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explore using bare app imports for reusability #146

Closed
terrablue opened this issue Jul 28, 2024 · 1 comment
Closed

explore using bare app imports for reusability #146

terrablue opened this issue Jul 28, 2024 · 1 comment
Labels
core core code dx developer experience

Comments

@terrablue
Copy link
Contributor

terrablue commented Jul 28, 2024

For both routes and components, it could be interesting to have an option to import them from another route or component for reusability without using relative imports, which are brittle.

Consider the following route in e.g. routes/base/add-head.js

// PROPOSED: not an actual route: do NOT map requests to `/base/add-head` to this
export const virtual = true;

export default route => ({
  head() {
    // return stuff like headers
  },
  // add all HTTP verbs from route (this could contain an overriding `head` verb)
  ...route,
});

And then in another route:

import base from "app/routes/base/add-head";

export default base({
  get() { ... },
});

This would allow any route to add a HEAD verb to it.

The same could be done with components, to allow reusing base components from anywhere within the components directory.

In itself, the app identifier means nothing (unless you're using the npm package app). But with the new build system, where we put everything inside build, we could add a package.json file there that defines

{
  "name": "app",
  "exports": {
    "./routes/*": "./routes/*.js",
    "./components/*": "./server/components/*.js"
  }
}

For the client-bundling, we'd need to pass in a dynamic tsconfig with paths to esbuild.

@terrablue terrablue added dx developer experience core core code labels Jul 28, 2024
@terrablue terrablue changed the title Explore using bare app imports for reusability explore using bare app imports for reusability Jul 31, 2024
@terrablue
Copy link
Contributor Author

closing in favour of the more general #159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core core code dx developer experience
Projects
None yet
Development

No branches or pull requests

1 participant