Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
c7955832
Unverified
Commit
c7955832
authored
Apr 23, 2019
by
Tim Neutkens
Committed by
GitHub
Apr 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Typescript compilation (#7110)
parent
78783477
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
75 additions
and
6 deletions
+75
-6
config.js
packages/next-server/server/config.js
+1
-1
preset.ts
packages/next/build/babel/preset.ts
+11
-2
webpack-config.ts
packages/next/build/webpack-config.ts
+2
-2
package.json
packages/next/package.json
+1
-1
hello.tsx
test/integration/basic/pages/typescript/hello.tsx
+5
-0
hmr.js
test/integration/basic/test/hmr.js
+36
-0
index.test.js
test/integration/basic/test/index.test.js
+2
-0
typescript.js
test/integration/basic/test/typescript.js
+17
-0
No files found.
packages/next-server/server/config.js
View file @
c7955832
...
...
@@ -14,7 +14,7 @@ const defaultConfig = {
useFileSystemPublicRoutes
:
true
,
generateBuildId
:
()
=>
null
,
generateEtags
:
true
,
pageExtensions
:
[
'jsx'
,
'js'
],
pageExtensions
:
[
'
tsx'
,
'ts'
,
'
jsx'
,
'js'
],
target
:
'server'
,
poweredByHeader
:
true
,
onDemandEntries
:
{
...
...
packages/next/build/babel/preset.ts
View file @
c7955832
...
...
@@ -44,7 +44,8 @@ type NextBabelPresetOptions = {
type
BabelPreset
=
{
presets
?:
PluginItem
[]
|
null
,
plugins
?:
PluginItem
[]
|
null
plugins
?:
PluginItem
[]
|
null
,
overrides
?:
any
[]
}
// Taken from https://github.com/babel/babel/commit/d60c5e1736543a6eac4b549553e107a9ba967051#diff-b4beead8ad9195361b4537601cc22532R158
...
...
@@ -91,6 +92,14 @@ module.exports = (api: any, options: NextBabelPresetOptions = {}): BabelPreset =
isProduction
&&
[
require
(
'babel-plugin-transform-react-remove-prop-types'
),
{
removeImport
:
true
}]
].
filter
(
Boolean
)
].
filter
(
Boolean
),
overrides
:
[
{
test
:
/
\.(
tsx|ts
)
$/
,
presets
:
[
require
(
'@babel/preset-typescript'
)
]
}
]
}
}
packages/next/build/webpack-config.ts
View file @
c7955832
...
...
@@ -236,12 +236,12 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, d
}
},
config
.
experimental
.
ampBindInitData
&&
!
isServer
&&
{
test
:
/
\.(
js|mjs|jsx
)
$/
,
test
:
/
\.(
tsx|ts|
js|mjs|jsx
)
$/
,
include
:
[
path
.
join
(
dir
,
'data'
)],
use
:
'next-data-loader'
},
{
test
:
/
\.(
js|mjs|jsx
)
$/
,
test
:
/
\.(
tsx|ts|
js|mjs|jsx
)
$/
,
include
:
[
dir
,
/next-server
[\\/]
dist
[\\/]
lib/
],
exclude
:
(
path
:
string
)
=>
{
if
(
/next-server
[\\/]
dist
[\\/]
lib/
.
test
(
path
))
{
...
...
packages/next/package.json
View file @
c7955832
...
...
@@ -39,6 +39,7 @@
]
},
"dependencies"
:
{
"@babel/preset-typescript"
:
"7.3.3"
,
"@babel/core"
:
"7.1.2"
,
"@babel/plugin-proposal-class-properties"
:
"7.1.0"
,
"@babel/plugin-proposal-object-rest-spread"
:
"7.0.0"
,
...
...
@@ -90,7 +91,6 @@
},
"devDependencies"
:
{
"@babel/parser"
:
"7.2.0"
,
"@babel/preset-typescript"
:
"7.3.3"
,
"@taskr/clear"
:
"1.1.0"
,
"@taskr/esnext"
:
"1.1.0"
,
"@taskr/watch"
:
"1.1.0"
,
...
...
test/integration/basic/pages/typescript/hello.tsx
0 → 100644
View file @
c7955832
import
React
from
'react'
export
default
function
Hello
():
JSX
.
Element
{
return
<
div
>
Hello World
</
div
>
}
test/integration/basic/test/hmr.js
View file @
c7955832
...
...
@@ -81,6 +81,42 @@ export default (context, renderViaHTTP) => {
}
})
it
(
'should detect the changes to typescript pages and display it'
,
async
()
=>
{
let
browser
try
{
browser
=
await
webdriver
(
context
.
appPort
,
'/typescript/hello'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/Hello World/
)
const
pagePath
=
join
(
__dirname
,
'../'
,
'pages'
,
'typescript'
,
'hello.tsx'
)
const
originalContent
=
readFileSync
(
pagePath
,
'utf8'
)
const
editedContent
=
originalContent
.
replace
(
'Hello World'
,
'COOL page'
)
// change the content
writeFileSync
(
pagePath
,
editedContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/COOL page/
)
// add the original content
writeFileSync
(
pagePath
,
originalContent
,
'utf8'
)
await
check
(
()
=>
getBrowserBodyText
(
browser
),
/Hello World/
)
}
finally
{
if
(
browser
)
{
await
browser
.
close
()
}
}
})
it
(
'should not reload unrelated pages'
,
async
()
=>
{
let
browser
try
{
...
...
test/integration/basic/test/index.test.js
View file @
c7955832
...
...
@@ -13,6 +13,7 @@ import hmr from './hmr'
import
errorRecovery
from
'./error-recovery'
import
dynamic
from
'./dynamic'
import
processEnv
from
'./process-env'
import
typescript
from
'./typescript'
const
context
=
{}
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
5
...
...
@@ -37,5 +38,6 @@ describe('Basic Features', () => {
dynamic
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
hmr
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
errorRecovery
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
typescript
(
context
,
(
p
,
q
)
=>
renderViaHTTP
(
context
.
appPort
,
p
,
q
))
processEnv
(
context
)
})
test/integration/basic/test/typescript.js
0 → 100644
View file @
c7955832
/* eslint-env jest */
import
cheerio
from
'cheerio'
export
default
(
context
,
render
)
=>
{
async
function
get
$
(
path
,
query
)
{
const
html
=
await
render
(
path
,
query
)
return
cheerio
.
load
(
html
)
}
describe
(
'Typescript'
,
()
=>
{
describe
(
'default behavior'
,
()
=>
{
it
(
'should render the page'
,
async
()
=>
{
const
$
=
await
get
$
(
'/typescript/hello'
)
expect
(
$
(
'body'
).
text
()).
toMatch
(
/Hello World/
)
})
})
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment