mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
feat(ts): add TSX support (#4613)
This commit is contained in:
parent
a17bb1704d
commit
4d5274215a
@ -45,7 +45,7 @@ export default class Builder {
|
|||||||
restart: null
|
restart: null
|
||||||
}
|
}
|
||||||
|
|
||||||
this.supportedExtensions = ['vue', 'js', 'ts']
|
this.supportedExtensions = ['vue', 'js', 'ts', 'tsx']
|
||||||
|
|
||||||
// Helper to resolve build paths
|
// Helper to resolve build paths
|
||||||
this.relativeToBuild = (...args) =>
|
this.relativeToBuild = (...args) =>
|
||||||
|
@ -47,6 +47,10 @@ export default () => ({
|
|||||||
transpileOnly: true,
|
transpileOnly: true,
|
||||||
appendTsSuffixTo: [/\.vue$/]
|
appendTsSuffixTo: [/\.vue$/]
|
||||||
},
|
},
|
||||||
|
tsx: {
|
||||||
|
transpileOnly: true,
|
||||||
|
appendTsxSuffixTo: [/\.vue$/]
|
||||||
|
},
|
||||||
vueStyle: {}
|
vueStyle: {}
|
||||||
},
|
},
|
||||||
styleResources: {},
|
styleResources: {},
|
||||||
|
@ -133,7 +133,7 @@ const sortRoutes = function sortRoutes(routes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const createRoutes = function createRoutes(files, srcDir, pagesDir = '', routeNameSplitter = '-') {
|
export const createRoutes = function createRoutes(files, srcDir, pagesDir = '', routeNameSplitter = '-') {
|
||||||
const supportedExtensions = ['vue', 'js', 'ts']
|
const supportedExtensions = ['vue', 'js', 'ts', 'tsx']
|
||||||
const routes = []
|
const routes = []
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
const keys = file
|
const keys = file
|
||||||
|
@ -234,6 +234,19 @@ export default class WebpackBaseConfig {
|
|||||||
loader: 'ts-loader',
|
loader: 'ts-loader',
|
||||||
options: this.loaders.ts
|
options: this.loaders.ts
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
test: /\.tsx$/,
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: this.getBabelOptions()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: 'ts-loader',
|
||||||
|
options: this.loaders.tsx
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
test: /\.css$/,
|
test: /\.css$/,
|
||||||
oneOf: styleLoader.apply('css')
|
oneOf: styleLoader.apply('css')
|
||||||
@ -392,7 +405,7 @@ export default class WebpackBaseConfig {
|
|||||||
hints: this.options.dev ? false : 'warning'
|
hints: this.options.dev ? false : 'warning'
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.wasm', '.mjs', '.js', '.json', '.vue', '.jsx', '.ts'],
|
extensions: ['.wasm', '.mjs', '.js', '.json', '.vue', '.jsx', '.ts', '.tsx'],
|
||||||
alias: this.alias(),
|
alias: this.alias(),
|
||||||
modules: webpackModulesDir
|
modules: webpackModulesDir
|
||||||
},
|
},
|
||||||
|
9
test/fixtures/typescript/pages/contact.tsx
vendored
Normal file
9
test/fixtures/typescript/pages/contact.tsx
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
|
||||||
|
export default Vue.extend({
|
||||||
|
name: 'Contact',
|
||||||
|
// @ts-ignore: h not used but needed to compile
|
||||||
|
render (h) {
|
||||||
|
return <div>Contact Page</div>
|
||||||
|
}
|
||||||
|
})
|
1
test/fixtures/typescript/tsconfig.json
vendored
1
test/fixtures/typescript/tsconfig.json
vendored
@ -7,6 +7,7 @@
|
|||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
|
"jsx": "preserve",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
|
@ -80,10 +80,10 @@ describe('basic dev', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('Config: build.loaders', () => {
|
test('Config: build.loaders', () => {
|
||||||
expect(Object.keys(loadersOptions)).toHaveLength(13)
|
expect(Object.keys(loadersOptions)).toHaveLength(14)
|
||||||
expect(loadersOptions).toHaveProperty(
|
expect(loadersOptions).toHaveProperty(
|
||||||
'file', 'fontUrl', 'imgUrl', 'pugPlain', 'vue',
|
'file', 'fontUrl', 'imgUrl', 'pugPlain', 'vue',
|
||||||
'css', 'cssModules', 'less', 'sass', 'scss', 'stylus', 'ts', 'vueStyle'
|
'css', 'cssModules', 'less', 'sass', 'scss', 'stylus', 'ts', 'tsx', 'vueStyle'
|
||||||
)
|
)
|
||||||
const { cssModules, vue } = loadersOptions
|
const { cssModules, vue } = loadersOptions
|
||||||
expect(cssModules.localIdentName).toBe('[hash:base64:6]')
|
expect(cssModules.localIdentName).toBe('[hash:base64:6]')
|
||||||
|
@ -25,6 +25,11 @@ describe('typescript', () => {
|
|||||||
expect(html).toContain('<div>Interface Page</div>')
|
expect(html).toContain('<div>Interface Page</div>')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('/contact', async () => {
|
||||||
|
const { html } = await nuxt.server.renderRoute('/contact')
|
||||||
|
expect(html).toContain('<div>Contact Page</div>')
|
||||||
|
})
|
||||||
|
|
||||||
// Close server and ask nuxt to stop listening to file changes
|
// Close server and ask nuxt to stop listening to file changes
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await nuxt.close()
|
await nuxt.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user