Skip to content

Commit c51a5af

Browse files
committed
feat: basic support for webpack 5
1 parent 51b3771 commit c51a5af

23 files changed

Lines changed: 176 additions & 360 deletions
-36.1 KB
Binary file not shown.
36.6 KB
Binary file not shown.
309 KB
Binary file not shown.
-9.06 KB
Binary file not shown.
-4.15 KB
Binary file not shown.

examples/vue-cssextract/webpack.config.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ module.exports = {
1919
use: BabelMultiTargetPlugin.loader(),
2020
}, {
2121
test: /\.vue$/,
22-
use: [
23-
BabelMultiTargetPlugin.loader('vue-loader'),
24-
],
22+
use: BabelMultiTargetPlugin.loader('vue-loader'),
2523
},
2624
{
2725
test: /\.css$/,
@@ -31,18 +29,4 @@ module.exports = {
3129
],
3230
}],
3331
},
34-
35-
node: {
36-
// prevent webpack from injecting useless setImmediate polyfill because Vue
37-
// source contains it (although only uses it if it's native).
38-
setImmediate: false,
39-
// prevent webpack from injecting mocks to Node native modules
40-
// that does not make sense for the client
41-
dgram: 'empty',
42-
fs: 'empty',
43-
net: 'empty',
44-
tls: 'empty',
45-
// eslint-disable-next-line camelcase
46-
child_process: 'empty',
47-
},
4832
}

examples/vue-dynamic-import/webpack.config.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,4 @@ module.exports = {
3838
},
3939
],
4040
},
41-
42-
node: {
43-
// prevent webpack from injecting useless setImmediate polyfill because Vue
44-
// source contains it (although only uses it if it's native).
45-
setImmediate: false,
46-
// prevent webpack from injecting mocks to Node native modules
47-
// that does not make sense for the client
48-
dgram: 'empty',
49-
fs: 'empty',
50-
net: 'empty',
51-
tls: 'empty',
52-
// eslint-disable-next-line camelcase
53-
child_process: 'empty',
54-
},
5541
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
},
6060
"peerDependencies": {
6161
"core-js": "^2.6.3 || ^3.6.5",
62-
"html-webpack-plugin": "^4.0.0",
62+
"html-webpack-plugin": "^5.0.0-alpha.6",
6363
"terser": ">=3.12.0",
6464
"webpack": "^5.0.0",
6565
"webpack-dev-server": "^3.1.0"
@@ -115,7 +115,7 @@
115115
"hard-source-webpack-plugin": "^0.13.1",
116116
"html-loader": "^1.1.0",
117117
"html-webpack-include-assets-plugin": "^2.0.0",
118-
"html-webpack-plugin": "^4.3.0",
118+
"html-webpack-plugin": "^5.0.0-alpha.6",
119119
"jasmine-core": "^3.6.0",
120120
"jasmine-spec-reporter": "^5.0.2",
121121
"mini-css-extract-plugin": "^0.9.0",

src/babel-target.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { BabelLoaderTransformOptions, BabelPresetOptions } from 'babel-loader'
2-
import * as webpack from 'webpack'
3-
import Chunk = webpack.Chunk
4-
import ChunkGroup = webpack.ChunkGroup
5-
import Entrypoint = webpack.Entrypoint
6-
import Module = webpack.Module
2+
import { Chunk, ChunkGroup, ChunkGraph, Entrypoint, Module } from 'webpack'
73

84
import { BabelLoaderCacheDirectoryOption } from './babel.multi.target.options'
95
import { BabelTargetOptions } from './babel.target.options'
@@ -33,8 +29,9 @@ export type BabelTargetInfo = { [TOption in keyof BabelTargetOptions]: BabelTarg
3329
// so, need to do this instead
3430
const SIG = {
3531
module: [
36-
'disconnect',
37-
'unseal',
32+
// These are removed in webpack@5
33+
// 'disconnect',
34+
// 'unseal',
3835
'isEntryModule',
3936
'isInChunk',
4037
],
@@ -51,7 +48,8 @@ const SIG = {
5148
'hasEntryModule',
5249
'addModule',
5350
'removeModule',
54-
'setModules',
51+
// This is removed in webpack@5
52+
// 'setModules',
5553
'getNumberOfModules',
5654
'addGroup',
5755
'isInGroup',
@@ -137,7 +135,7 @@ export class BabelTarget implements BabelTargetInfo {
137135
}
138136

139137
public static getTargetFromModule(module: Module): BabelTarget {
140-
if (module.options && module.options.babelTarget) {
138+
if (module.options?.babelTarget) {
141139
return module.options.babelTarget
142140
}
143141

@@ -146,7 +144,7 @@ export class BabelTarget implements BabelTargetInfo {
146144
}
147145

148146
for (const reason of module.reasons) {
149-
if (reason.dependency && reason.dependency.babelTarget) {
147+
if (reason.dependency?.babelTarget) {
150148
return reason.dependency.babelTarget
151149
}
152150
if (reason.module) {
@@ -162,10 +160,16 @@ export class BabelTarget implements BabelTargetInfo {
162160
}
163161

164162
public static getTargetFromEntrypoint(entrypoint: Entrypoint): BabelTarget {
165-
if (!entrypoint.runtimeChunk.hasEntryModule()) {
163+
if (!entrypoint.getRuntimeChunk().hasEntryModule()) {
166164
return undefined
167165
}
168-
return BabelTarget.getTargetFromModule(entrypoint.runtimeChunk.entryModule)
166+
const arr = Array.from(
167+
ChunkGraph.getChunkGraphForChunk(
168+
entrypoint.getRuntimeChunk(),
169+
'Chunk.entryModule',
170+
'DEP_WEBPACK_CHUNK_ENTRY_MODULE',
171+
).getChunkEntryModulesIterable(entrypoint.getRuntimeChunk()))
172+
return BabelTarget.getTargetFromModule(arr[0])
169173
}
170174

171175
// eslint-disable-next-line

src/babel.multi.target.html.updater.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ export class BabelMultiTargetHtmlUpdater implements Plugin {
9090

9191
// not sure if this is a problem since webpack will wait for dependencies to load, but sorting
9292
// by auto/dependency will result in a cyclic dependency error for lazy-loaded routes
93-
htmlWebpackPlugin.options.chunksSortMode = 'none' as any
93+
htmlWebpackPlugin.userOptions.chunksSortMode = 'none' as any
9494

95-
if ((htmlWebpackPlugin.options.chunks as any) !== 'all' &&
96-
htmlWebpackPlugin.options.chunks &&
97-
htmlWebpackPlugin.options.chunks.length
95+
if ((htmlWebpackPlugin.userOptions.chunks as any) !== 'all' &&
96+
htmlWebpackPlugin.userOptions.chunks &&
97+
htmlWebpackPlugin.userOptions.chunks.length
9898
) {
99-
htmlWebpackPlugin.options.chunks = this.mapChunkNames(htmlWebpackPlugin.options.chunks as string[])
99+
htmlWebpackPlugin.userOptions.chunks = this.mapChunkNames(htmlWebpackPlugin.userOptions.chunks as string[])
100100
}
101101

102-
if (htmlWebpackPlugin.options.excludeChunks &&
103-
htmlWebpackPlugin.options.excludeChunks.length) {
104-
htmlWebpackPlugin.options.excludeChunks = this.mapChunkNames(htmlWebpackPlugin.options.excludeChunks)
102+
if (htmlWebpackPlugin.userOptions.excludeChunks &&
103+
htmlWebpackPlugin.userOptions.excludeChunks.length) {
104+
htmlWebpackPlugin.userOptions.excludeChunks = this.mapChunkNames(htmlWebpackPlugin.userOptions.excludeChunks)
105105
}
106106

107107
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation: Compilation) => {

0 commit comments

Comments
 (0)