Skip to content
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

fix: make ssr-build-plugin compatible with webpack4/5 (fix #11718) #11814

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/server/template-renderer/index.js
Expand Up @@ -55,7 +55,7 @@ export default class TemplateRenderer {
this.inject = options.inject !== false
// if no template option is provided, the renderer is created
// as a utility object for rendering assets like preload links and scripts.

const { template } = options
this.parsedTemplate = template
? typeof template === 'string'
Expand Down Expand Up @@ -224,7 +224,7 @@ export default class TemplateRenderer {
if (this.clientManifest) {
const initial = this.preloadFiles.filter(({ file }) => isJS(file))
const async = (this.getUsedAsyncFiles(context) || []).filter(({ file }) => isJS(file))
const needed = [initial[0]].concat(async, initial.slice(1))
const needed = [].concat(initial[0] ? [initial[0]] : [], async, initial.slice(1));
return needed.map(({ file }) => {
return `<script src="${this.publicPath}${file}" defer></script>`
}).join('')
Expand Down
14 changes: 14 additions & 0 deletions src/server/webpack-plugin/client.js
Expand Up @@ -19,6 +19,20 @@ export default class VueSSRClientPlugin {
const initialFiles = uniq(Object.keys(stats.entrypoints)
.map(name => stats.entrypoints[name].assets)
.reduce((assets, all) => all.concat(assets), [])
.map(function (file) {
if (typeof file === "string") {
return file;
}

if (
Object.prototype.toString.call(file) === "[object Object]" &&
file.name
) {
return file.name;
}

throw new Error(`file structure is not correct: ${file}`);
})
.filter((file) => isJS(file) || isCSS(file)))

const asyncFiles = allFiles
Expand Down
19 changes: 18 additions & 1 deletion src/server/webpack-plugin/server.js
Expand Up @@ -20,7 +20,21 @@ export default class VueSSRServerPlugin {
return cb()
}

const entryAssets = entryInfo.assets.filter(isJS)
const entryAssets = entryInfo.assets
.map(function (file) {
if (typeof file === "string") {
return file;
}

if (
Object.prototype.toString.call(file) === "[object Object]" &&
file.name
) {
return file.name;
}

throw new Error(`file structure is not correct: ${file}`);
}).filter(isJS)

if (entryAssets.length > 1) {
throw new Error(
Expand All @@ -45,6 +59,9 @@ export default class VueSSRServerPlugin {
stats.assets.forEach(asset => {
if (isJS(asset.name)) {
bundle.files[asset.name] = compilation.assets[asset.name].source()
if (asset.info && asset.info.related && asset.info.related.sourceMap) {
bundle.maps[asset.info.related.sourceMap.replace(/\.map$/, '')] = JSON.parse(compilation.assets[asset.info.related.sourceMap].source());
}
} else if (asset.name.match(/\.js\.map$/)) {
bundle.maps[asset.name.replace(/\.map$/, '')] = JSON.parse(compilation.assets[asset.name].source())
}
Expand Down