-
Notifications
You must be signed in to change notification settings - Fork 48
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
Webpack require context support #208
Comments
Hey @hanstf 👋 This is purely webpack-related and I'm not sure how it could work if
Well, this is effectively what the Does that make sense? |
Hi @pkosiec, Thank you for your quick reply! Let me give more context on this, currently our project is a monorepo applications, with some common libraries that compile with webpack and we configured it not to compile the node modules so mongo-seeding is not compiled and imported as it is from node modules. We also configured 2 entry points in webpack, 1 for the main node js server and the other one is to perform seed. We are trying 2 ways to integrate with mongo-seeding in our seed entry point:
we can set entry point for each seed file but it will be too tedious and will create a lot of duplicate codes 2nd way that we are using now is we are excerpting the populator code with require.context method from webpack to dynamically include a file into the compiled code
So would be great if mongo-seeding provides an API instead of supplying a path, we can supply an array of folder and method to get the content/even the content itself. Similar to knex custom seed source, https://knexjs.org/guide/migrations.html#custom-seed-sources. Sorry for this long explanation, you may ignore if this is not something related to mongo-seeding |
Hi @hanstf, From what I understood, you'd still like to use most of the logic of I'm thinking about the following options:
interface CollectionSource {
getDirectories: () => Promise<CollectionDirectory>;
}
interface CollectionDirectory {
name: string;
getFiles: () => Promise<CollectionFile>;
}
interface CollectionFile {
read: () => Promise<unknown>;
} or interface CollectionSource {
getDirectories: () => Promise<string[]>;
listFiles: (directory: string) => Promise<string[]>;
readFile: () => Promise<unknown>;
} What I dislike in this approach is that it is still somewhat tied to filesystem 🤔 Maybe there's a more elegant way to abstract it? 🤔 Of course the
What do you think? |
This is a great tools and we have been using it for a while.
Recently we would like to build our code with webpack and planning to use the require.context to build all of the seed files. It would be great if mongo-seeding able to read from the context as well. Or can take the inspiration of knex seeding's seedSource option where we can supply the method to get the content and the list of the folders.
The text was updated successfully, but these errors were encountered: