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

Customization on what files get picked up by pages/ #1689

Closed
jupl opened this issue Apr 11, 2017 · 2 comments
Closed

Customization on what files get picked up by pages/ #1689

jupl opened this issue Apr 11, 2017 · 2 comments

Comments

@jupl
Copy link

jupl commented Apr 11, 2017

My understanding is the file system in pages/ is what defines the routing for the application. Currently it appears to be finding files that has a .js extension. I'm trying to use Next.js in a custom server written entirely in TypeScript and am hitting a wall.

  • Because Next.js only recognizes .js files in pages/, I cannot use .tsx files even if I add a loader (ts-loader, awesome-typescript-loader) to Webpack via next.config.js.
  • If I precompile the TypeScript files in pages/ using tsc, it's going to compile files that are shared by both server and pages/. That puts me in a quandary:
    • If compile the code to be server friendly (ES2015 without import/export and no JSX), I get more verbose code and debugging becomes a pain, plus I assume I lose tree shaking capabilities in Webpack.
    • If I compile the code to be more up to date as per the examples in the README, I need to use Babel when running my server code and possibly have to fight Next.js' Babel config.
    • I can't take advantage of tools like ts-node because compiled .js files are picked first over any .ts/.tsx files.
  • When I write tests for my projects, I like to have them either next to my source files or use Jest's __tests__ neighboring folder. Unfortunately, this presents a problem in the pages/ directory.

I'm thinking that a result it would be nice if next.config.js could have an option that allows one to specify which files in pages/ should get picked up by Next for routing/compilation, which defaults to the current behavior of picking up all .js files. It can be for instance a function that provides as an argument the path of a file in pages/ and returns a boolean to indicate if the file should be processed or excluded. This is my repo/branch I'm playing around trying to get things to work. I'm sure there's other things I'm doing wrong as I'm trying out things via trial and error, but the compilation/extension issue is a roadblock. I figure I would open up an issue for tracking since I've asked around and have heard no answers, which makes sense if everyone is busy.

@arunoda
Copy link
Contributor

arunoda commented Apr 11, 2017

Currently it's only .js. It's unlikely, we'll change it on the short term.
And we want to go with the least amount of options as possible we can.
I would suggest you to play with some babel-plugin for this.

@jrmyio
Copy link

jrmyio commented May 19, 2017

Also came accross this problem.

Typescript is getting more and more popular these days. It would be a shame if you can't get it to work with Next.js. @arunoda can you reconsider?

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants