Skip to content

Commit 80e3086

Browse files
authored
fix: better compatible with webpack v4/v5 (#52)
1 parent ab0fbe2 commit 80e3086

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

.changeset/dirty-olives-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-server-renderer": patch
3+
---
4+
5+
fix: better compatible with webpack v4/v5

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/*

src/webpack-plugin/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ export class ReactSSRServerPlugin implements WebpackPluginInstance {
3838

3939
const entry = entryAssets[0]
4040
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
41-
if (!entry || typeof entry !== 'string') {
41+
if (!entry) {
4242
throw new Error(
4343
`Entry "${entryName}" not found. Did you specify the correct entry option?`,
4444
)
4545
}
4646

4747
const bundle = {
48-
entry,
48+
entry: typeof entry === 'string' ? entry : entry.name,
4949
files: {} as Record<string, Buffer | string>,
5050
maps: {} as Record<string, unknown>,
5151
}

src/webpack-plugin/util.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ export const warn = (msg: string) => console.error(red(`${prefix} ${msg}\n`))
99
export const tip = (msg: string) => console.log(yellow(`${prefix} ${msg}\n`))
1010

1111
export const validate = (compiler: Compiler) => {
12-
if (compiler.options.target !== 'node') {
12+
const { externals, output, target } = compiler.options
13+
14+
if (target !== 'node') {
1315
warn('webpack config `target` should be "node".')
1416
}
1517

1618
if (
19+
output.library?.type !== 'commonjs2' &&
1720
// @ts-expect-error -- compatibility
18-
compiler.options.output.libraryTarget !== 'commonjs2'
21+
output.libraryTarget !== 'commonjs2'
1922
) {
2023
warn('webpack config `output.libraryTarget` should be "commonjs2".')
2124
}
2225

23-
if (!compiler.options.externals) {
26+
if (!externals) {
2427
tip(
2528
'It is recommended to externalize dependencies in the server build for ' +
2629
'better build performance.',

0 commit comments

Comments
 (0)