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

extract route traversin/parsing webpack plugin to separate module #150

Open
Guria opened this issue Apr 19, 2023 · 2 comments
Open

extract route traversin/parsing webpack plugin to separate module #150

Guria opened this issue Apr 19, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@Guria
Copy link

Guria commented Apr 19, 2023

You have implemented a good module which can be used for more potential use cases.
I personally would like to have it for making custom navigation that will be auto generated from available routes.
I see that you can have an can pass a callback option to NextJSRoutesPlugin.
This callback will accept parsed data from routes and will do code generation.

class NextJSRoutesPlugin implements WebpackPluginInstance {

  apply() {
    // ...
    if (this.context.dev) {
      const watcher = watch(watchDirs, {
        persistent: true,
      });
      // batch changes
      const generate = debounce(() => this.processRoutes, 50);
      watcher.on("add", generate).on("unlink", generate);
    } else {
      this.processRoutes();
    }
  }
  collectRoutes() {
    const defaultOptions = {
      // ...
    };
    const opts = {
      ...defaultOptions,
      ...this.options,
    };
    // ...
    return nextRoutes(files);
  }
  processRoutes: () => {
    this.options.callback(this.collectRoutes)
  }
}
  config.plugins.push(
    new NextJSRoutesPlugin(nextConfig, context, {
      ...options,
      callback: (routes) => {
        const generated = generate(routes, options);
        writeFileSync(outputFilepath, generated);        
      }
    })
  );
@tatethurston
Copy link
Owner

Hey @Guria this is a cool idea, I’d be happy to look into supporting this use case. Could you tell me a little more about the code generation you would like to do?

@Guria
Copy link
Author

Guria commented Apr 20, 2023

I'd like to have something like on the https://ariakit.org/
image

It is also made with Next JS https://github.com/ariakit/ariakit/blob/main/website/build-pages/pages-webpack-plugin.js

In my case I don't need a full text search, but I will definetely will need some meta information like titles, descriptions, etc.
It may be defined in route pages files or collocated in yml files. So potentially we will need to also be able to inject logic in traversing and not only just receiving final result.

@tatethurston tatethurston added the help wanted Extra attention is needed label Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants