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
695f372d
Unverified
Commit
695f372d
authored
Sep 14, 2018
by
Tim Neutkens
Committed by
GitHub
Sep 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compile away next/link proptypes in production (#5155)
This saves 7KB as prop-types-exact is not needed in production.
parent
5d147a82
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
27 deletions
+41
-27
webpack.js
build/webpack.js
+9
-0
error.js
lib/error.js
+6
-4
link.js
lib/link.js
+26
-23
No files found.
build/webpack.js
View file @
695f372d
...
...
@@ -245,6 +245,15 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i
}),
dev
&&
!
isServer
&&
new
FriendlyErrorsWebpackPlugin
(),
new
webpack
.
IgnorePlugin
(
/
(
precomputed
)
/
,
/node_modules.+
(
elliptic
)
/
),
// This removes prop-types-exact in production, as it's not used there.
!
dev
&&
new
webpack
.
IgnorePlugin
({
checkResource
:
(
resource
)
=>
{
return
/prop-types-exact/
.
test
(
resource
)
},
checkContext
:
(
context
)
=>
{
return
context
.
indexOf
(
NEXT_PROJECT_ROOT_DIST
)
!==
-
1
}
}),
// Even though require.cache is server only we have to clear assets from both compilations
// This is because the client compilation generates the build manifest that's used on the server side
dev
&&
new
NextJsRequireCacheHotReloader
(),
...
...
lib/error.js
View file @
695f372d
...
...
@@ -9,10 +9,6 @@ export default class Error extends React.Component {
return
{
statusCode
}
}
static
propTypes
=
{
statusCode
:
PropTypes
.
number
}
render
()
{
const
{
statusCode
}
=
this
.
props
const
title
=
statusCode
===
404
...
...
@@ -35,6 +31,12 @@ export default class Error extends React.Component {
}
}
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
Error
.
propTypes
=
{
statusCode
:
PropTypes
.
number
}
}
const
styles
=
{
error
:
{
color
:
'#000'
,
...
...
lib/link.js
View file @
695f372d
...
...
@@ -3,7 +3,6 @@
import
{
resolve
,
format
,
parse
}
from
'url'
import
React
,
{
Component
,
Children
}
from
'react'
import
PropTypes
from
'prop-types'
import
exact
from
'prop-types-exact'
import
Router
,
{
_rewriteUrlForNextExport
}
from
'./router'
import
{
warn
,
execOnce
,
getLocationOrigin
}
from
'./utils'
...
...
@@ -35,28 +34,6 @@ function memoizedFormatUrl (formatUrl) {
}
class
Link
extends
Component
{
static
propTypes
=
exact
({
href
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]).
isRequired
,
as
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]),
prefetch
:
PropTypes
.
bool
,
replace
:
PropTypes
.
bool
,
shallow
:
PropTypes
.
bool
,
passHref
:
PropTypes
.
bool
,
scroll
:
PropTypes
.
bool
,
children
:
PropTypes
.
oneOfType
([
PropTypes
.
element
,
(
props
,
propName
)
=>
{
const
value
=
props
[
propName
]
if
(
typeof
value
===
'string'
)
{
warnLink
(
`Warning: You're using a string directly inside <Link>. This usage has been deprecated. Please add an <a> tag as child of <Link>`
)
}
return
null
}
]).
isRequired
})
componentDidMount
()
{
this
.
prefetch
()
}
...
...
@@ -177,4 +154,30 @@ class Link extends Component {
}
}
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
// This module gets removed by webpack.IgnorePlugin
const
exact
=
require
(
'prop-types-exact'
)
Link
.
propTypes
=
exact
({
href
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]).
isRequired
,
as
:
PropTypes
.
oneOfType
([
PropTypes
.
string
,
PropTypes
.
object
]),
prefetch
:
PropTypes
.
bool
,
replace
:
PropTypes
.
bool
,
shallow
:
PropTypes
.
bool
,
passHref
:
PropTypes
.
bool
,
scroll
:
PropTypes
.
bool
,
children
:
PropTypes
.
oneOfType
([
PropTypes
.
element
,
(
props
,
propName
)
=>
{
const
value
=
props
[
propName
]
if
(
typeof
value
===
'string'
)
{
warnLink
(
`Warning: You're using a string directly inside <Link>. This usage has been deprecated. Please add an <a> tag as child of <Link>`
)
}
return
null
}
]).
isRequired
})
}
export
default
Link
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