From dfaffc0183fbf08bf158db54bf6aac63cf752050 Mon Sep 17 00:00:00 2001 From: Kevin Marrec Date: Sat, 12 Jan 2019 21:21:21 +0100 Subject: [PATCH] feat(nuxt-ts): typescript support improvements (#4750) --- examples/typescript-vuex/tsconfig.json | 4 ++-- examples/typescript/tsconfig.json | 4 ++-- packages/cli/src/utils/index.js | 2 +- packages/webpack/src/config/base.js | 23 +++++++++++++---------- test/fixtures/typescript/tsconfig.json | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/examples/typescript-vuex/tsconfig.json b/examples/typescript-vuex/tsconfig.json index 6ec8fa2719..a7c0574ccc 100644 --- a/examples/typescript-vuex/tsconfig.json +++ b/examples/typescript-vuex/tsconfig.json @@ -1,9 +1,9 @@ { "compilerOptions": { - "target": "es5", + "target": "esnext", "module": "esnext", "moduleResolution": "node", - "lib": ["es2015", "dom"], + "lib": ["esnext", "esnext.asynciterable", "dom"], "esModuleInterop": true, "experimentalDecorators": true, "allowJs": true, diff --git a/examples/typescript/tsconfig.json b/examples/typescript/tsconfig.json index 6ec8fa2719..a7c0574ccc 100644 --- a/examples/typescript/tsconfig.json +++ b/examples/typescript/tsconfig.json @@ -1,9 +1,9 @@ { "compilerOptions": { - "target": "es5", + "target": "esnext", "module": "esnext", "moduleResolution": "node", - "lib": ["es2015", "dom"], + "lib": ["esnext", "esnext.asynciterable", "dom"], "esModuleInterop": true, "experimentalDecorators": true, "allowJs": true, diff --git a/packages/cli/src/utils/index.js b/packages/cli/src/utils/index.js index 57535f5864..9575579f7a 100644 --- a/packages/cli/src/utils/index.js +++ b/packages/cli/src/utils/index.js @@ -9,7 +9,7 @@ import chalk from 'chalk' import prettyBytes from 'pretty-bytes' import env from 'std-env' -export const requireModule = esm(module, { +export const requireModule = process.env.NUXT_TS ? require : esm(module, { cache: false, cjs: { cache: true, diff --git a/packages/webpack/src/config/base.js b/packages/webpack/src/config/base.js index d0ad1bb279..20672940cb 100644 --- a/packages/webpack/src/config/base.js +++ b/packages/webpack/src/config/base.js @@ -185,6 +185,10 @@ export default class WebpackBaseConfig { this.nuxt, { isServer: this.isServer, perfLoader } ) + const babelLoader = { + loader: require.resolve('babel-loader'), + options: this.getBabelOptions() + } return [ { @@ -224,23 +228,22 @@ export default class WebpackBaseConfig { // item in transpile can be string or regex object return !this.modulesToTranspile.some(module => module.test(file)) }, - use: perfLoader.js().concat({ - loader: require.resolve('babel-loader'), - options: this.getBabelOptions() - }) + use: perfLoader.js().concat(babelLoader) }, { test: /\.ts$/i, - loader: 'ts-loader', - options: this.loaders.ts + use: [ + babelLoader, + { + loader: 'ts-loader', + options: this.loaders.ts + } + ] }, { test: /\.tsx$/i, use: [ - { - loader: require.resolve('babel-loader'), - options: this.getBabelOptions() - }, + babelLoader, { loader: 'ts-loader', options: this.loaders.tsx diff --git a/test/fixtures/typescript/tsconfig.json b/test/fixtures/typescript/tsconfig.json index ad236887a0..5fb28f47e0 100644 --- a/test/fixtures/typescript/tsconfig.json +++ b/test/fixtures/typescript/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "esnext", "module": "esnext", "moduleResolution": "node", "lib": ["esnext", "esnext.asynciterable", "dom"],