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
dfe6d148
Unverified
Commit
dfe6d148
authored
May 17, 2020
by
Tim Neutkens
Committed by
GitHub
May 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Experimental] Add support for production browser source maps (#13018)
parent
9f8076be
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
163 additions
and
1 deletion
+163
-1
webpack-config.ts
packages/next/build/webpack-config.ts
+3
-0
base.ts
packages/next/build/webpack/config/blocks/base.ts
+6
-1
index.ts
packages/next/build/webpack/config/index.ts
+3
-0
utils.ts
packages/next/build/webpack/config/utils.ts
+1
-0
config.ts
packages/next/next-server/server/config.ts
+1
-0
next.config.js
.../integration/production-browser-sourcemaps/next.config.js
+5
-0
ssr.js
test/integration/production-browser-sourcemaps/pages/ssr.js
+13
-0
static.js
...integration/production-browser-sourcemaps/pages/static.js
+13
-0
serverless-server.js
...ration/production-browser-sourcemaps/serverless-server.js
+58
-0
index.test.js
...egration/production-browser-sourcemaps/test/index.test.js
+60
-0
No files found.
packages/next/build/webpack-config.ts
View file @
dfe6d148
...
@@ -136,6 +136,8 @@ export default async function getBaseWebpackConfig(
...
@@ -136,6 +136,8 @@ export default async function getBaseWebpackConfig(
entrypoints
:
WebpackEntrypoints
entrypoints
:
WebpackEntrypoints
}
}
):
Promise
<
webpack
.
Configuration
>
{
):
Promise
<
webpack
.
Configuration
>
{
const
productionBrowserSourceMaps
=
config
.
experimental
.
productionBrowserSourceMaps
&&
!
isServer
let
plugins
:
PluginMetaData
[]
=
[]
let
plugins
:
PluginMetaData
[]
=
[]
let
babelPresetPlugins
:
{
dir
:
string
;
config
:
any
}[]
=
[]
let
babelPresetPlugins
:
{
dir
:
string
;
config
:
any
}[]
=
[]
...
@@ -1032,6 +1034,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1032,6 +1034,7 @@ export default async function getBaseWebpackConfig(
isServer
,
isServer
,
assetPrefix
:
config
.
assetPrefix
||
''
,
assetPrefix
:
config
.
assetPrefix
||
''
,
sassOptions
:
config
.
sassOptions
,
sassOptions
:
config
.
sassOptions
,
productionBrowserSourceMaps
,
})
})
if
(
typeof
config
.
webpack
===
'function'
)
{
if
(
typeof
config
.
webpack
===
'function'
)
{
...
...
packages/next/build/webpack/config/blocks/base.ts
View file @
dfe6d148
...
@@ -25,7 +25,12 @@ export const base = curry(function base(
...
@@ -25,7 +25,12 @@ export const base = curry(function base(
config
.
devtool
=
'eval-source-map'
config
.
devtool
=
'eval-source-map'
}
}
}
else
{
}
else
{
config
.
devtool
=
false
// Enable browser sourcemaps
if
(
ctx
.
productionBrowserSourceMaps
)
{
config
.
devtool
=
'source-map'
}
else
{
config
.
devtool
=
false
}
}
}
if
(
!
config
.
module
)
{
if
(
!
config
.
module
)
{
...
...
packages/next/build/webpack/config/index.ts
View file @
dfe6d148
...
@@ -12,6 +12,7 @@ export async function build(
...
@@ -12,6 +12,7 @@ export async function build(
isServer
,
isServer
,
assetPrefix
,
assetPrefix
,
sassOptions
,
sassOptions
,
productionBrowserSourceMaps
,
}:
{
}:
{
rootDirectory
:
string
rootDirectory
:
string
customAppFile
:
string
|
null
customAppFile
:
string
|
null
...
@@ -19,6 +20,7 @@ export async function build(
...
@@ -19,6 +20,7 @@ export async function build(
isServer
:
boolean
isServer
:
boolean
assetPrefix
:
string
assetPrefix
:
string
sassOptions
:
any
sassOptions
:
any
productionBrowserSourceMaps
:
boolean
}
}
):
Promise
<
webpack
.
Configuration
>
{
):
Promise
<
webpack
.
Configuration
>
{
const
ctx
:
ConfigurationContext
=
{
const
ctx
:
ConfigurationContext
=
{
...
@@ -34,6 +36,7 @@ export async function build(
...
@@ -34,6 +36,7 @@ export async function build(
:
assetPrefix
:
assetPrefix
:
''
,
:
''
,
sassOptions
,
sassOptions
,
productionBrowserSourceMaps
,
}
}
const
fn
=
pipe
(
base
(
ctx
),
css
(
ctx
))
const
fn
=
pipe
(
base
(
ctx
),
css
(
ctx
))
...
...
packages/next/build/webpack/config/utils.ts
View file @
dfe6d148
...
@@ -13,6 +13,7 @@ export type ConfigurationContext = {
...
@@ -13,6 +13,7 @@ export type ConfigurationContext = {
assetPrefix
:
string
assetPrefix
:
string
sassOptions
:
any
sassOptions
:
any
productionBrowserSourceMaps
:
boolean
}
}
export
type
ConfigurationFn
=
(
export
type
ConfigurationFn
=
(
...
...
packages/next/next-server/server/config.ts
View file @
dfe6d148
...
@@ -52,6 +52,7 @@ const defaultConfig: { [key: string]: any } = {
...
@@ -52,6 +52,7 @@ const defaultConfig: { [key: string]: any } = {
workerThreads
:
false
,
workerThreads
:
false
,
basePath
:
''
,
basePath
:
''
,
pageEnv
:
false
,
pageEnv
:
false
,
productionBrowserSourceMaps
:
false
,
},
},
future
:
{
future
:
{
excludeDefaultMomentLocales
:
false
,
excludeDefaultMomentLocales
:
false
,
...
...
test/integration/production-browser-sourcemaps/next.config.js
0 → 100644
View file @
dfe6d148
module
.
exports
=
{
experimental
:
{
productionBrowserSourceMaps
:
true
,
},
}
test/integration/production-browser-sourcemaps/pages/ssr.js
0 → 100644
View file @
dfe6d148
export
default
function
SSRPage
({
data
})
{
return
<
div
>
{
data
.
foo
}
<
/div
>
}
export
async
function
getServerSideProps
()
{
return
{
props
:
{
data
:
{
foo
:
'bar'
,
},
},
}
}
test/integration/production-browser-sourcemaps/pages/static.js
0 → 100644
View file @
dfe6d148
export
default
function
StaticPage
({
data
})
{
return
<
div
>
{
data
.
foo
}
<
/div
>
}
export
async
function
getStaticProps
()
{
return
{
props
:
{
data
:
{
foo
:
'bar'
,
},
},
}
}
test/integration/production-browser-sourcemaps/serverless-server.js
0 → 100644
View file @
dfe6d148
// This is not the correct way to implement the Next.js serverless target for production traffic
// It is only used for testing cases of rendering specific pages in the integration test suite
const
path
=
require
(
'path'
)
const
http
=
require
(
'http'
)
const
send
=
require
(
'send'
)
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
if
(
req
.
url
===
'/ssr'
)
{
return
require
(
'./.next/serverless/pages/ssr.js'
).
render
(
req
,
res
)
}
if
(
req
.
url
===
'/getinitialprops'
)
{
return
require
(
'./.next/serverless/pages/getinitialprops.js'
).
render
(
req
,
res
)
}
if
(
req
.
url
===
'/api/api-route'
)
{
return
require
(
'./.next/serverless/pages/api/api-route.js'
).
default
(
req
,
res
)
}
if
(
req
.
url
===
'/user/a'
)
{
return
send
(
req
,
path
.
join
(
__dirname
,
'.next/serverless/pages/user/a.html'
)
).
pipe
(
res
)
}
if
(
req
.
url
===
'/user/b'
)
{
return
send
(
req
,
path
.
join
(
__dirname
,
'.next/serverless/pages/user/b.html'
)
).
pipe
(
res
)
}
if
(
req
.
url
===
'/static'
)
{
return
send
(
req
,
path
.
join
(
__dirname
,
'.next/serverless/pages/static.html'
)
).
pipe
(
res
)
}
if
(
req
.
url
.
startsWith
(
'/_next'
))
{
send
(
req
,
path
.
join
(
__dirname
,
'.next'
,
req
.
url
.
split
(
'/_next'
).
pop
())
).
pipe
(
res
)
}
})
server
.
listen
(
process
.
env
.
PORT
,
()
=>
{
console
.
log
(
'ready on'
,
process
.
env
.
PORT
)
})
test/integration/production-browser-sourcemaps/test/index.test.js
0 → 100644
View file @
dfe6d148
/* eslint-env jest */
import
fs
from
'fs-extra'
import
{
join
}
from
'path'
import
{
nextBuild
}
from
'next-test-utils'
import
{
recursiveReadDir
}
from
'next/dist/lib/recursive-readdir'
jest
.
setTimeout
(
1000
*
60
*
2
)
const
appDir
=
join
(
__dirname
,
'../'
)
const
nextConfig
=
join
(
appDir
,
'next.config.js'
)
let
nextConfigContent
function
runTests
()
{
it
(
'includes sourcemaps for all browser files'
,
async
()
=>
{
const
browserFiles
=
await
recursiveReadDir
(
join
(
appDir
,
'.next'
,
'static'
),
/.*/
)
const
jsFiles
=
browserFiles
.
filter
(
file
=>
file
.
endsWith
(
'.js'
)
&&
file
.
includes
(
'/pages/'
)
)
jsFiles
.
forEach
(
file
=>
{
expect
(
browserFiles
.
includes
(
`
${
file
}
.map`
)).
toBe
(
true
)
})
})
}
describe
(
'Production browser sourcemaps'
,
()
=>
{
describe
(
'Server support'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
nextBuild
(
appDir
,
[],
{})
})
runTests
()
})
describe
(
'Serverless support'
,
()
=>
{
beforeAll
(
async
()
=>
{
nextConfigContent
=
await
fs
.
readFile
(
nextConfig
,
'utf8'
)
await
fs
.
writeFile
(
nextConfig
,
`
module.exports = {
target: 'serverless',
experimental: {
productionBrowserSourceMaps: true
}
}
`
)
await
nextBuild
(
appDir
,
[],
{})
})
afterAll
(
async
()
=>
{
await
fs
.
writeFile
(
nextConfig
,
nextConfigContent
)
})
runTests
()
})
})
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