From e7f87ce01e81fec74acc8ce2b225950de35c403e Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sat, 14 Sep 2019 21:17:21 +0200 Subject: [PATCH] Update next-typescript readme --- packages/next-typescript/babel.js | 5 -- packages/next-typescript/index.js | 63 ------------------ packages/next-typescript/package.json | 11 ---- packages/next-typescript/readme.md | 94 +-------------------------- 4 files changed, 1 insertion(+), 172 deletions(-) delete mode 100644 packages/next-typescript/babel.js delete mode 100644 packages/next-typescript/index.js delete mode 100644 packages/next-typescript/package.json diff --git a/packages/next-typescript/babel.js b/packages/next-typescript/babel.js deleted file mode 100644 index 682e7931..00000000 --- a/packages/next-typescript/babel.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = () => { - return { - presets: [require('@babel/preset-typescript')] - } -} diff --git a/packages/next-typescript/index.js b/packages/next-typescript/index.js deleted file mode 100644 index 0c3797cf..00000000 --- a/packages/next-typescript/index.js +++ /dev/null @@ -1,63 +0,0 @@ -module.exports = (nextConfig = {}) => { - if (!nextConfig.pageExtensions) { - nextConfig.pageExtensions = ['jsx', 'js'] - } - - if (nextConfig.pageExtensions.indexOf('ts') === -1) { - nextConfig.pageExtensions.unshift('ts') - } - - if (nextConfig.pageExtensions.indexOf('tsx') === -1) { - nextConfig.pageExtensions.unshift('tsx') - } - - if (nextConfig.typescriptLoaderOptions) { - throw new Error( - '`typescriptLoaderOptions` in next.config.js is no longer supported. https://err.sh/next-plugins/typescript-loader-options' - ) - } - - return Object.assign({}, nextConfig, { - webpack(config, options) { - const path = require('path') - if (!options.defaultLoaders) { - throw new Error( - 'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade' - ) - } - - const { dir, defaultLoaders, dev, isServer } = options - - config.resolve.extensions.push('.ts', '.tsx') - - // Backwards compatibility with older versions of Next.js. - // Next.js will automatically apply hot-self-accept-loader for all extensions in `pageExtensions` - // Which next-typescript adds itself to - if (!defaultLoaders.hotSelfAccept) { - if (dev && !isServer) { - config.module.rules.push({ - test: /\.(ts|tsx)$/, - loader: 'hot-self-accept-loader', - include: [path.join(dir, 'pages')], - options: { - extensions: /\.(ts|tsx)$/ - } - }) - } - } - - config.module.rules.push({ - test: /\.(ts|tsx)$/, - include: [dir], - exclude: /node_modules/, - use: defaultLoaders.babel - }) - - if (typeof nextConfig.webpack === 'function') { - return nextConfig.webpack(config, options) - } - - return config - } - }) -} diff --git a/packages/next-typescript/package.json b/packages/next-typescript/package.json deleted file mode 100644 index bf9c8a29..00000000 --- a/packages/next-typescript/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "@zeit/next-typescript", - "version": "1.1.2-canary.0", - "main": "index.js", - "license": "MIT", - "repository": "zeit/next-plugins", - "dependencies": { - "@babel/preset-typescript": "^7.0.0" - }, - "gitHead": "31e8978d07e5468f760a222a72d1e8f3f457e6ff" -} diff --git a/packages/next-typescript/readme.md b/packages/next-typescript/readme.md index 902c5f5c..1041389d 100644 --- a/packages/next-typescript/readme.md +++ b/packages/next-typescript/readme.md @@ -1,95 +1,3 @@ # Next.js + Typescript -Use [Typescript](https://www.typescriptlang.org/) with [Next.js](https://github.com/zeit/next.js) - -This plugin implements [@babel/preset-typescript](https://github.com/babel/babel/tree/master/packages/babel-preset-typescript) with Next.js. - -## Installation - -``` -npm install --save @zeit/next-typescript -``` - -or - -``` -yarn add @zeit/next-typescript -``` - -## Usage - -Create a `next.config.js` in your project - -```js -// next.config.js -const withTypescript = require('@zeit/next-typescript') -module.exports = withTypescript({ - /* config options here */ -}) -``` - -Create a `.babelrc` in your project - -```js -{ - "presets": [ - "next/babel", - "@zeit/next-typescript/babel" - ] -} -``` - -Create a `tsconfig.json` in your project - -```json -{ - "compilerOptions": { - "allowJs": true, - "allowSyntheticDefaultImports": true, - "jsx": "preserve", - "lib": ["dom", "es2017"], - "module": "esnext", - "moduleResolution": "node", - "noEmit": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "preserveConstEnums": true, - "removeComments": false, - "skipLibCheck": true, - "sourceMap": true, - "strict": true, - "target": "esnext" - } -} -``` - -Optionally you can add your custom Next.js configuration as parameter - -```js -// next.config.js -const withTypescript = require('@zeit/next-typescript') -module.exports = withTypescript({ - webpack(config, options) { - return config - } -}) -``` - -### Type checking - -If your IDE or code editor don't provide satisfying TypeScript support, or you want to see error list in console output, you can use [`fork-ts-checker-webpack-plugin`](https://github.com/Realytics/fork-ts-checker-webpack-plugin). It will not increase compile time because it forks type checking in a separate process - -```js -// next.config.js -const withTypescript = require("@zeit/next-typescript") -const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); - -module.exports = withTypescript({ - webpack(config, options) { - // Do not run type checking twice: - if (options.isServer) config.plugins.push(new ForkTsCheckerWebpackPlugin()) - - return config - } -}) -``` +TypeScript is supported in Next.js out of the box. You can find the documentation here: https://nextjs.org/docs#typescript