Skip to content

Loader Configuration #98

@tubbo

Description

@tubbo

With chained loaders being considered as part of this effort, it might become pretty unruly for large apps to benefit from using loaders to help shore up some of the hairy and error-prone sides of the app.

A real-world example here is a TypeScript app that uses GraphQL, Pug, and SQL queries that all need to be loaded using readFile(). When building this app, special care must be taken for these files which will not be included in the build from TS since it has no awareness of their existence. But if we could import those files, this would no longer be a problem. Tools can statically analyze the imports and determine which files need to be included in the build artifact, and that's a huge win over not just the current strategy, but other languages as well.

This poses a problem, though. How are these loaders going to be maintained for all the various commands you need to run? Does every developer need to have a huge $NODE_OPTIONS defined to ensure the app loads correctly?

I think this could be solved by allowing developers the option to define what loaders are to be run within a package.json. This would allow someone to communicate how loading should work in code, which is transferable to anyone else working on the project.

In keeping with the convention of other JS tools, the configuration should probably be nested in an object of its own rather than be defined on the top level:

{
  "node": {
    "loaders": []
  }
}

This array would be anything importable: a module, file path, etc.

Just a suggestion, and I'm willing to help work this out. But this is very interesting to me as I think loaders in node would open the door to a lot of quality of life improvements, like more sophisticated package management, lint tooling, and all kinds of stuff.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions