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
10408241
Unverified
Commit
10408241
authored
Jul 09, 2020
by
Tim Neutkens
Committed by
GitHub
Jul 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make serverless-plugin compatible with webpack 5 (#15010)
Co-authored-by:
Zack Jackson
<
zackary.l.jackson@gmail.com
>
parent
6d7cf2a9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
16 deletions
+30
-16
serverless-plugin.ts
packages/next/build/webpack/plugins/serverless-plugin.ts
+30
-16
No files found.
packages/next/build/webpack/plugins/serverless-plugin.ts
View file @
10408241
import
{
Compiler
}
from
'webpack'
import
{
Compiler
}
from
'webpack'
import
{
connectChunkAndModule
}
from
'webpack/lib/GraphHelpers'
import
webpack
from
'webpack'
const
isWebpack5
=
parseInt
(
webpack
.
version
!
)
===
5
const
GraphHelpers
=
isWebpack5
?
undefined
:
require
(
'webpack/lib/GraphHelpers'
)
/**
/**
* Makes sure there are no dynamic chunks when the target is serverless
* Makes sure there are no dynamic chunks when the target is serverless
...
@@ -10,24 +15,33 @@ import { connectChunkAndModule } from 'webpack/lib/GraphHelpers'
...
@@ -10,24 +15,33 @@ import { connectChunkAndModule } from 'webpack/lib/GraphHelpers'
export
class
ServerlessPlugin
{
export
class
ServerlessPlugin
{
apply
(
compiler
:
Compiler
)
{
apply
(
compiler
:
Compiler
)
{
compiler
.
hooks
.
compilation
.
tap
(
'ServerlessPlugin'
,
(
compilation
)
=>
{
compiler
.
hooks
.
compilation
.
tap
(
'ServerlessPlugin'
,
(
compilation
)
=>
{
compilation
.
hooks
.
optimizeChunksBasic
.
tap
(
const
hook
=
isWebpack5
'ServerlessPlugin'
,
?
compilation
.
hooks
.
optimizeChunks
(
chunks
)
=>
{
:
compilation
.
hooks
.
optimizeChunksBasic
chunks
.
forEach
((
chunk
)
=>
{
hook
.
tap
(
'ServerlessPlugin'
,
(
chunks
)
=>
{
for
(
const
chunk
of
chunks
)
{
// If chunk is not an entry point skip them
// If chunk is not an entry point skip them
if
(
chunk
.
hasEntryModule
())
{
if
(
!
chunk
.
hasEntryModule
())
{
continue
}
// Async chunks are usages of import() for example
const
dynamicChunks
=
chunk
.
getAllAsyncChunks
()
const
dynamicChunks
=
chunk
.
getAllAsyncChunks
()
if
(
dynamicChunks
.
size
!==
0
)
{
for
(
const
dynamicChunk
of
dynamicChunks
)
{
for
(
const
dynamicChunk
of
dynamicChunks
)
{
for
(
const
module
of
dynamicChunk
.
modulesIterable
)
{
for
(
const
module
of
dynamicChunk
.
modulesIterable
)
{
connectChunkAndModule
(
chunk
,
module
)
if
(
isWebpack5
)
{
// Add module back into the entry chunk
chunk
.
addModule
(
module
)
continue
}
}
// Webpack 4 has separate GraphHelpers
GraphHelpers
.
connectChunkAndModule
(
chunk
,
module
)
}
}
}
}
}
}
})
})
}
)
})
})
}
}
}
}
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