New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ssr): vue-ssr-webpack-plugin compatible with webpack 5 #12002
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { validate, isJS, onEmit } from './util' | ||
import { validate, isJS, getAssetName, onEmit } from './util' | ||
|
||
export default class VueSSRServerPlugin { | ||
constructor (options = {}) { | ||
|
@@ -10,7 +10,8 @@ export default class VueSSRServerPlugin { | |
apply (compiler) { | ||
validate(compiler) | ||
|
||
onEmit(compiler, 'vue-server-plugin', (compilation, cb) => { | ||
const stage = 'PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just put the stage name in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sodatea client plugin and server plugin are applied in different stage, so I think it's better to specify the stage name here. |
||
onEmit(compiler, 'vue-server-plugin', stage, (compilation, cb) => { | ||
const stats = compilation.getStats().toJson() | ||
const entryName = Object.keys(stats.entrypoints)[0] | ||
const entryInfo = stats.entrypoints[entryName] | ||
|
@@ -20,7 +21,9 @@ export default class VueSSRServerPlugin { | |
return cb() | ||
} | ||
|
||
const entryAssets = entryInfo.assets.filter(isJS) | ||
const entryAssets = entryInfo.assets | ||
.map(getAssetName) | ||
.filter(isJS) | ||
|
||
if (entryAssets.length > 1) { | ||
throw new Error( | ||
|
@@ -42,14 +45,14 @@ export default class VueSSRServerPlugin { | |
maps: {} | ||
} | ||
|
||
stats.assets.forEach(asset => { | ||
if (isJS(asset.name)) { | ||
bundle.files[asset.name] = compilation.assets[asset.name].source() | ||
} else if (asset.name.match(/\.js\.map$/)) { | ||
bundle.maps[asset.name.replace(/\.map$/, '')] = JSON.parse(compilation.assets[asset.name].source()) | ||
Object.keys(compilation.assets).forEach(name => { | ||
if (isJS(name)) { | ||
bundle.files[name] = compilation.assets[name].source() | ||
} else if (name.match(/\.js\.map$/)) { | ||
bundle.maps[name.replace(/\.map$/, '')] = JSON.parse(compilation.assets[name].source()) | ||
} | ||
// do not emit anything else for server | ||
delete compilation.assets[asset.name] | ||
delete compilation.assets[name] | ||
}) | ||
|
||
const json = JSON.stringify(bundle, null, 2) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an optional peer dependency.
Users should be able to use this package without webpack.