@@ -4,7 +4,6 @@ import { readFileSync } from 'fs'
44import chalk from 'next/dist/compiled/chalk'
55import TerserPlugin from 'next/dist/compiled/terser-webpack-plugin'
66import path from 'path'
7- import PnpWebpackPlugin from 'pnp-webpack-plugin'
87import webpack from 'webpack'
98import {
109 DOT_NEXT_ALIAS ,
@@ -37,7 +36,6 @@ import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin'
3736import { CssMinimizerPlugin } from './webpack/plugins/css-minimizer-plugin'
3837import { JsConfigPathsPlugin } from './webpack/plugins/jsconfig-paths-plugin'
3938import { DropClientPage } from './webpack/plugins/next-drop-client-page-plugin'
40- import NextEsmPlugin from './webpack/plugins/next-esm-plugin'
4139import NextJsSsrImportPlugin from './webpack/plugins/nextjs-ssr-import'
4240import NextJsSSRModuleCachePlugin from './webpack/plugins/nextjs-ssr-module-cache'
4341import PagesManifestPlugin from './webpack/plugins/pages-manifest-plugin'
@@ -302,7 +300,7 @@ export default async function getBaseWebpackConfig(
302300 plugins : isWebpack5
303301 ? // webpack 5+ has the PnP resolver built-in by default:
304302 [ ]
305- : [ PnpWebpackPlugin ] ,
303+ : [ require ( 'pnp-webpack-plugin' ) ] ,
306304 }
307305
308306 const webpackMode = dev ? 'development' : 'production'
@@ -347,13 +345,17 @@ export default async function getBaseWebpackConfig(
347345 cacheGroups : {
348346 default : false ,
349347 vendors : false ,
348+ // In webpack 5 vendors was renamed to defaultVendors
349+ defaultVendors : false ,
350350 } ,
351351 } ,
352352 prodGranular : {
353353 chunks : 'all' ,
354354 cacheGroups : {
355355 default : false ,
356356 vendors : false ,
357+ // In webpack 5 vendors was renamed to defaultVendors
358+ defaultVendors : false ,
357359 framework : {
358360 chunks : 'all' ,
359361 name : 'framework' ,
@@ -736,7 +738,7 @@ export default async function getBaseWebpackConfig(
736738 'node_modules' ,
737739 ...nodePathList , // Support for NODE_PATH environment variable
738740 ] ,
739- plugins : [ PnpWebpackPlugin ] ,
741+ plugins : isWebpack5 ? [ ] : [ require ( 'pnp-webpack-plugin' ) ] ,
740742 } ,
741743 module : {
742744 rules : [
@@ -881,7 +883,10 @@ export default async function getBaseWebpackConfig(
881883 // solution that requires the user to opt into importing specific locales.
882884 // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
883885 config . future . excludeDefaultMomentLocales &&
884- new webpack . IgnorePlugin ( / ^ \. \/ l o c a l e $ / , / m o m e n t $ / ) ,
886+ new webpack . IgnorePlugin ( {
887+ resourceRegExp : / ^ \. \/ l o c a l e $ / ,
888+ contextRegExp : / m o m e n t $ / ,
889+ } ) ,
885890 ...( dev
886891 ? ( ( ) => {
887892 // Even though require.cache is server only we have to clear assets from both compilations
@@ -931,22 +936,25 @@ export default async function getBaseWebpackConfig(
931936 config . experimental . modern &&
932937 ! isServer &&
933938 ! dev &&
934- new NextEsmPlugin ( {
935- filename : ( getFileName : Function | string ) => ( ...args : any [ ] ) => {
936- const name =
937- typeof getFileName === 'function'
938- ? getFileName ( ...args )
939- : getFileName
940-
941- return name . includes ( '.js' )
942- ? name . replace ( / \. j s $ / , '.module.js' )
943- : escapePathVariables (
944- args [ 0 ] . chunk . name . replace ( / \. j s $ / , '.module.js' )
945- )
946- } ,
947- chunkFilename : ( inputChunkName : string ) =>
948- inputChunkName . replace ( / \. j s $ / , '.module.js' ) ,
949- } ) ,
939+ ( ( ) => {
940+ const { NextEsmPlugin } = require ( './webpack/plugins/next-esm-plugin' )
941+ return new NextEsmPlugin ( {
942+ filename : ( getFileName : Function | string ) => ( ...args : any [ ] ) => {
943+ const name =
944+ typeof getFileName === 'function'
945+ ? getFileName ( ...args )
946+ : getFileName
947+
948+ return name . includes ( '.js' )
949+ ? name . replace ( / \. j s $ / , '.module.js' )
950+ : escapePathVariables (
951+ args [ 0 ] . chunk . name . replace ( / \. j s $ / , '.module.js' )
952+ )
953+ } ,
954+ chunkFilename : ( inputChunkName : string ) =>
955+ inputChunkName . replace ( / \. j s $ / , '.module.js' ) ,
956+ } )
957+ } ) ( ) ,
950958 config . experimental . conformance &&
951959 ! dev &&
952960 new WebpackConformancePlugin ( {
0 commit comments