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
8c175e5d
Commit
8c175e5d
authored
Mar 25, 2019
by
Joe Haddad
Committed by
Tim Neutkens
Mar 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace `buildId` well known string during output (#6782)
* Replace buildId well known string during output * Fix linting
parent
480fb565
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
47 deletions
+48
-47
webpack-config.ts
packages/next/build/webpack-config.ts
+1
-1
serverless-plugin.ts
packages/next/build/webpack/plugins/serverless-plugin.ts
+47
-46
No files found.
packages/next/build/webpack-config.ts
View file @
8c175e5d
...
@@ -303,7 +303,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, isServe
...
@@ -303,7 +303,7 @@ export default function getBaseWebpackConfig (dir: string, {dev = false, isServe
return
/next-server
[\\/]
dist
[\\/]
/
.
test
(
context
)
||
/next
[\\/]
dist
[\\/]
/
.
test
(
context
)
return
/next-server
[\\/]
dist
[\\/]
/
.
test
(
context
)
||
/next
[\\/]
dist
[\\/]
/
.
test
(
context
)
}
}
}),
}),
target
===
'serverless'
&&
isServer
&&
new
ServerlessPlugin
(
buildId
,
{
sourceMap
:
dev
}
),
target
===
'serverless'
&&
isServer
&&
new
ServerlessPlugin
(
buildId
),
target
!==
'serverless'
&&
isServer
&&
new
PagesManifestPlugin
(),
target
!==
'serverless'
&&
isServer
&&
new
PagesManifestPlugin
(),
target
!==
'serverless'
&&
isServer
&&
new
NextJsSSRModuleCachePlugin
({
outputPath
}),
target
!==
'serverless'
&&
isServer
&&
new
NextJsSSRModuleCachePlugin
({
outputPath
}),
isServer
&&
new
NextJsSsrImportPlugin
(),
isServer
&&
new
NextJsSsrImportPlugin
(),
...
...
packages/next/build/webpack/plugins/serverless-plugin.ts
View file @
8c175e5d
import
{
Compiler
}
from
'webpack'
import
{
Compiler
}
from
'webpack'
import
{
SourceMapSource
,
RawSource
}
from
'webpack-sources'
import
GraphHelpers
from
'webpack/lib/GraphHelpers'
import
GraphHelpers
from
'webpack/lib/GraphHelpers'
/**
/**
...
@@ -10,16 +9,60 @@ import GraphHelpers from 'webpack/lib/GraphHelpers'
...
@@ -10,16 +9,60 @@ import GraphHelpers from 'webpack/lib/GraphHelpers'
const
NEXT_REPLACE_BUILD_ID
=
'__NEXT_REPLACE__BUILD_ID__'
const
NEXT_REPLACE_BUILD_ID
=
'__NEXT_REPLACE__BUILD_ID__'
function
replaceInBuffer
(
buffer
:
Buffer
,
from
:
string
,
to
:
string
)
{
const
target
=
Buffer
.
from
(
from
,
'utf8'
)
const
replacement
=
Buffer
.
from
(
to
,
'utf8'
)
function
bufferTee
(
source
:
Buffer
):
Buffer
{
const
index
=
source
.
indexOf
(
target
)
if
(
index
===
-
1
)
{
// Escape recursion loop
return
source
}
const
b1
=
source
.
slice
(
0
,
index
)
const
b2
=
source
.
slice
(
index
+
target
.
length
)
const
nextBuffer
=
bufferTee
(
b2
)
return
Buffer
.
concat
(
[
b1
,
replacement
,
nextBuffer
],
index
+
replacement
.
length
+
nextBuffer
.
length
)
}
return
bufferTee
(
buffer
)
}
function
interceptFileWrites
(
compiler
:
Compiler
,
contentFn
:
(
input
:
Buffer
)
=>
Buffer
)
{
compiler
.
outputFileSystem
=
new
Proxy
(
compiler
.
outputFileSystem
,
{
get
(
target
,
propKey
)
{
const
orig
=
(
target
as
any
)[
propKey
]
if
(
propKey
!==
'writeFile'
)
{
return
orig
}
return
function
(
targetPath
:
string
,
content
:
Buffer
,
...
args
:
any
[])
{
return
orig
.
call
(
target
,
targetPath
,
contentFn
(
content
),
...
args
)
}
},
})
}
export
class
ServerlessPlugin
{
export
class
ServerlessPlugin
{
private
buildId
:
string
private
buildId
:
string
private
sourceMap
:
boolean
constructor
(
buildId
:
string
,
{
sourceMap
=
false
}
=
{}
)
{
constructor
(
buildId
:
string
)
{
this
.
buildId
=
buildId
this
.
buildId
=
buildId
this
.
sourceMap
=
sourceMap
}
}
apply
(
compiler
:
Compiler
)
{
apply
(
compiler
:
Compiler
)
{
interceptFileWrites
(
compiler
,
content
=>
replaceInBuffer
(
content
,
NEXT_REPLACE_BUILD_ID
,
this
.
buildId
)
)
compiler
.
hooks
.
compilation
.
tap
(
'ServerlessPlugin'
,
compilation
=>
{
compiler
.
hooks
.
compilation
.
tap
(
'ServerlessPlugin'
,
compilation
=>
{
compilation
.
hooks
.
optimizeChunksBasic
.
tap
(
'ServerlessPlugin'
,
chunks
=>
{
compilation
.
hooks
.
optimizeChunksBasic
.
tap
(
'ServerlessPlugin'
,
chunks
=>
{
chunks
.
forEach
(
chunk
=>
{
chunks
.
forEach
(
chunk
=>
{
...
@@ -35,48 +78,6 @@ export class ServerlessPlugin {
...
@@ -35,48 +78,6 @@ export class ServerlessPlugin {
}
}
}
}
})
})
compilation
.
hooks
.
afterOptimizeChunkAssets
.
tap
(
'ServerlessPlugin'
,
chunks
=>
{
chunks
.
reduce
(
(
acc
,
chunk
)
=>
acc
.
concat
(
chunk
.
files
||
[]),
[]
as
any
[]
)
.
forEach
(
file
=>
{
const
asset
=
compilation
.
assets
[
file
]
let
input
let
inputSourceMap
if
(
this
.
sourceMap
)
{
if
(
asset
.
sourceAndMap
)
{
const
sourceAndMap
=
asset
.
sourceAndMap
()
inputSourceMap
=
sourceAndMap
.
map
input
=
sourceAndMap
.
source
}
else
{
inputSourceMap
=
asset
.
map
()
input
=
asset
.
source
()
}
}
else
{
input
=
asset
.
source
()
}
const
output
=
input
.
replace
(
NEXT_REPLACE_BUILD_ID
,
this
.
buildId
)
if
(
this
.
sourceMap
&&
inputSourceMap
)
{
compilation
.
assets
[
file
]
=
new
SourceMapSource
(
output
,
file
,
inputSourceMap
)
}
else
{
compilation
.
assets
[
file
]
=
new
RawSource
(
output
)
}
})
}
)
})
})
})
})
}
}
...
...
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