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

Adding Typescript loader in next.config.js #607

Closed
jagreehal opened this issue Jan 1, 2017 · 4 comments
Closed

Adding Typescript loader in next.config.js #607

jagreehal opened this issue Jan 1, 2017 · 4 comments

Comments

@jagreehal
Copy link
Contributor

jagreehal commented Jan 1, 2017

With #222 merged any ideas how to add a loader for TypeScript in next.config.js?

I've tried adding a TypeScript specific loader like this

const path = require('path');
const nextPagesDir = path.join(__dirname, 'pages');

const typescriptLoader = {
  test: /\.ts(x?)$/,
  loader: ['ts-loader'],
  exclude: /node_modules/,
  include: [
    nextPagesDir
  ]
};

module.exports = {
  webpack: (config) => {
    config.module.rules.push(typescriptLoader);
    return config;
  }
}

but assume additional changes need to be made as well as additional entries for hot loading etc.

Another question is should the TypeScript loader be used in with babel e.g.

loaders: ['babel-loader', 'ts-loader']

If so I'd need to apply the same babel options as in webpack.js.

@rauchg
Copy link
Member

rauchg commented Jan 1, 2017

This would be a terrific example to add! ./examples/with-typescript

@giacomorebonato
Copy link

I think that now the problem is that Next is looking only for files with .js extension in the pages folder, but with TypeScript we have .tsx

@timneutkens
Copy link
Member

Duplicate of #96. Closing in favor of that one.
Regarding the extensions (.ts/.tsx). There is a comment about adding custom extensions here: #544 (at the bottom)

@nelak
Copy link

nelak commented Jun 15, 2017

I was able to get this working in #2250 if anyone wants to take a look a it

@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

5 participants