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

feat: Webpack 5 Experimental Support #10885

Conversation

ScriptedAlchemy
Copy link
Contributor

@ScriptedAlchemy ScriptedAlchemy commented Mar 8, 2020

This is a WIP PR to add Webpack 5 support to next.js

There are some outstanding areas that will need work. But it's functional.

  • on-demand-entries-handler needs to be rewritten and provide WP4 & WP5 compatibility
  • formatMessages needs to be updated to parse output messages again, most of it is commented out right now
  • Solution to selectively install WP5 or WP4 along with upgrading dev-middleware
  • EsmPlugin - Needs a dependency factory because MiltiEntryPlugin was removed
  • TypeScript definitions and types need some updates
  • require cache is messed up in dev mode, likely due to on-demand-entries-handler - a workaround I'm using is uncachedRequire
  • Module not found: Error: Can't resolve 'pnpapi' in '/next.js/node_modules/enhanced-resolve/lib'" When doing a seerverless build
  • cleanup hot-reloader
  • API routes are not found.

This pull request is also needed.
vercel/next-plugins#620

I am publishing all this code to npm under module-federation org https://github.com/module-federation

console.log()

result = formatWebpackMessages(result)
console.log('There were errors!')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

needs to be fixed

@@ -34,14 +34,13 @@ import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin'
import { CssMinimizerPlugin } from './webpack/plugins/css-minimizer-plugin'
import { importAutoDllPlugin } from './webpack/plugins/dll-import'
import { DropClientPage } from './webpack/plugins/next-drop-client-page-plugin'
import NextEsmPlugin from './webpack/plugins/next-esm-plugin'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

broken in WP5, will address later

)
if (!webpack5Experiential) {
// Not needed with webpack 5
const AutoDllPlugin = importAutoDllPlugin({ distDir })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WP5 has its own cache, and its faast

@ScriptedAlchemy ScriptedAlchemy force-pushed the canary-backport-wp5-to-zeit branch from fc21eb9 to fab520b Compare March 17, 2020 03:01
ScriptedAlchemy and others added 9 commits March 28, 2020 11:45
Enabling module federation & suspense SSR
Enabling module federation & suspense SSR
* disable hmr in dev move

* feat: Upgrade Next.js to Webpack 5

Enabling module federation & suspense SSR

* fix: dirty patch for missing router context

* fix: dirty patch for missing router context

* fix: dirty patch for missing router context

* fix: dirty patch for missing router context

* fix: use dirty patch on server
* v9.3.2-beta.0

* v9.3.2-beta.1

* v9.3.2-beta.2

* v9.3.2-beta.3

* fix:

* docs: update readme
@ScriptedAlchemy ScriptedAlchemy force-pushed the canary-backport-wp5-to-zeit branch from fab520b to ee0680c Compare April 9, 2020 21:39
@ScriptedAlchemy ScriptedAlchemy changed the base branch from canary to master April 9, 2020 21:39
@ScriptedAlchemy ScriptedAlchemy force-pushed the canary-backport-wp5-to-zeit branch 5 times, most recently from e6120c3 to 7fba66b Compare April 9, 2020 21:53
@@ -120,7 +120,13 @@ export default singletonRouter as SingletonRouter
export { default as withRouter } from './with-router'

export function useRouter() {
return React.useContext(RouterContext)
if (process.browser) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need some help on this one, HMR or SSG seems to lose context

@@ -442,6 +442,8 @@ export async function renderToHTML(
const router = new ServerRouter(pathname, query, asPath, {
isFallback: isFallback,
})
global.router = router
Copy link
Contributor Author

Choose a reason for hiding this comment

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

another hack, losing context during HMR or SSG

* v9.3.2-beta.0

* v9.3.2-beta.1

* v9.3.2-beta.2

* v9.3.2-beta.3

* fix:

* docs: update readme
@ScriptedAlchemy ScriptedAlchemy force-pushed the canary-backport-wp5-to-zeit branch from 7fba66b to f8bd32e Compare April 9, 2020 22:01
@ScriptedAlchemy
Copy link
Contributor Author

ScriptedAlchemy commented Apr 9, 2020

Against master, 1700 tests pass. Most failures are around HMR or SSG - I resolved many of these with workarounds. The remaining tests are mostly related to format messages

@timneutkens Willing and ready to work with your team on this upgrade. From my perspective, its pretty far along.

Canary introduces some changes which I'm not sure how to address, like externals for webpack-dev-server which no longer exist in v4 rc

While in there, it would be great if we can support the ability to use ModuleFederation - this does not need to be part of next.js core, but it would be nice to try it out and see if there are any adjustments that would enable its use. I'm willing to open an additional PR for this aspect as well, perhaps at a later stage

@balazsorban44 balazsorban44 mentioned this pull request May 25, 2020
13 tasks
@timneutkens
Copy link
Member

Going to close this as I've built out the webpack 5 support, only thing left is some fast refresh tests that aren't passing.

Related PRs:
#13759
#13870
#13937
#14130
#14176
#14268
#14279
#14413
#14498
#14527
#14626
#14722
#14793

@timneutkens timneutkens closed this Jul 4, 2020
@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants