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

Initial updates for webpack 5 support #101

Merged
merged 12 commits into from Jun 10, 2021

Conversation

brophdawg11
Copy link
Owner

@brophdawg11 brophdawg11 commented Jun 1, 2021

The webpack@5 upgrade is mostly smooth with one exception. vue-server-renderer's webpack plugins are not updated to be webpack@5 compatible. The issues are documented in this github issue which doesn't seem to have a lot of traction (assuming the core team is more focused on Vue3 at the moment).

However, thankfully there is a really useful patch-package npm package that lets your store a patch file in your repo and uses a postinstall hook to apply that patch to the underlying package after installation. So instead of forking the vue-server-renderer repo to make the changes, we can instead store a patch in the parent repo that will apply the changes to the specific 2.6.12 version.

This is a bit more streamlined as a fork of the repo and still requires us to update the patch if we were to update vue-server-renderer, but avoids the need for a different forked repo entirely and keeps the applied changes for more explicit and easy to unravel.

There is a small demo app using this webpack@5 build available at https://github.com/brophdawg11/vue-ssr-build-demo-app

npm package changes:

# Remove this since we had only previously added it since we couldn't update it parent dependency
npm uninstall --save tar

# Add more peer deps that we use internally
npm i --save vuex vue-router memory-fs

# Update webpack-related packages to latest
npm i --save css-loader@5.2.6 mini-css-extract-plugin@1.6.0 optimize-css-assets-webpack-plugin@6.0.0 postcss-loader@5.3.0 sass@1.34.0 sass-loader@11.1.1 svg-url-loader@7.1.1 terser-webpack-plugin@5.1.2 vue-loader@15.9.7 vue-style-loader@4.1.3 webpack@5.37.1 webpack-cli@4.7.0 webpack-dev-middleware@4.3.0

# Added but eventually removed and lifted to app package.json
npm i --save patch-package

@@ -71,26 +66,12 @@ module.exports = {
logLevel,
getBaseConfig(config) {
return {
mode: environment,
devtool: isProd ? 'source-map' : 'eval-source-map',
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to the client build so we don't have to turn it off for server builds

'@store': path.resolve(config.rootDir, 'src/store'),
},
extensions: ['*', '.js', '.vue', '.json'],
},
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change - no longer providing anything out of the box here - this configuration is left up to the consuming application build

} catch (e) {
opts.logger.error(`Error parsing meta tag content: ${opts.initialStateMetaTag}`);
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change - no longer using this and instead relying on the application to use the opts.initialState approach

app.use(webpackDevMiddleware(clientCompiler, { outputFileSystem: mfs }));
app.use(webpackHotMiddleware(clientCompiler, { heartbeat: 5000 }));

clientCompiler.hooks.done.tap('setup-dev-server', (clientStats) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compiler.plugin is removed in favor of hooks

app.use(webpackHotMiddleware(clientCompiler, { heartbeat: 5000 }));
// Launch the sever webpack build
if (!serverCompiler) {
console.error('Launching server webpack build');
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to make the initial build sequential to avoid a ConcurrentCompilationError

@brophdawg11 brophdawg11 changed the base branch from main to feature/webpack5 June 4, 2021 13:25
@brophdawg11 brophdawg11 merged commit 2503b63 into feature/webpack5 Jun 10, 2021
@brophdawg11 brophdawg11 deleted the brophdawg11/webpack5 branch June 10, 2021 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant