diff --git a/packages/next/build/bundles/autodll-webpack-plugin.js b/packages/next/build/bundles/autodll-webpack-plugin.js new file mode 100644 index 0000000000000000000000000000000000000000..981afb03728e88879f0afc0fd79c12122dac87c2 --- /dev/null +++ b/packages/next/build/bundles/autodll-webpack-plugin.js @@ -0,0 +1,14 @@ +const path = require('path') + +module.exports = distDir => { + const autodllCachePath = path.resolve( + path.join(distDir, 'cache', 'autodll-webpack-plugin') + ) + + const autoDllWebpackPluginPaths = require('autodll-webpack-plugin/lib/paths') + autoDllWebpackPluginPaths.cacheDir = autodllCachePath + autoDllWebpackPluginPaths.getManifestPath = hash => bundleName => + path.resolve(autodllCachePath, hash, `${bundleName}.manifest.json`) + + return require('autodll-webpack-plugin') +} diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index d9be1a2ae8185d0434aafe7286c8dce141b2908e..a57f73111ecae93d98293e57c5767cf1698fc7bf 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -34,7 +34,6 @@ import { pluginLoaderOptions } from './webpack/loaders/next-plugin-loader' import BuildManifestPlugin from './webpack/plugins/build-manifest-plugin' 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' import NextJsSsrImportPlugin from './webpack/plugins/nextjs-ssr-import' @@ -813,7 +812,9 @@ export default async function getBaseWebpackConfig( ] if (!isServer) { - const AutoDllPlugin = importAutoDllPlugin({ distDir }) + const AutoDllPlugin = require('next/dist/compiled/autodll-webpack-plugin')( + distDir + ) devPlugins.push( new AutoDllPlugin({ filename: '[name]_[hash].js', diff --git a/packages/next/build/webpack/plugins/dll-import.ts b/packages/next/build/webpack/plugins/dll-import.ts deleted file mode 100644 index 50477ac67653c817692338cf97831d0aedaf8cc3..0000000000000000000000000000000000000000 --- a/packages/next/build/webpack/plugins/dll-import.ts +++ /dev/null @@ -1,23 +0,0 @@ -import path from 'path' - -export function importAutoDllPlugin({ distDir }: { distDir: string }) { - const autodllPaths = path.join( - path.dirname(require.resolve('autodll-webpack-plugin')), - 'paths.js' - ) - require(autodllPaths) - - const autodllCachePath = path.resolve( - path.join(distDir, 'cache', 'autodll-webpack-plugin') - ) - require.cache[autodllPaths] = Object.assign({}, require.cache[autodllPaths], { - exports: Object.assign({}, require.cache[autodllPaths].exports, { - cacheDir: autodllCachePath, - getManifestPath: (hash: string) => (bundleName: string) => - path.resolve(autodllCachePath, hash, `${bundleName}.manifest.json`), - }), - }) - - const AutoDllPlugin = require('autodll-webpack-plugin') - return AutoDllPlugin -} diff --git a/packages/next/package.json b/packages/next/package.json index 81aca129d66c891535cfb13192d9f0b246b627ce..a79156a0b5273f4b5eb8a6318d4b4b06202a51aa 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -74,7 +74,6 @@ "@babel/preset-typescript": "7.7.2", "@babel/runtime": "7.7.2", "@babel/types": "7.7.4", - "autodll-webpack-plugin": "0.4.2", "babel-loader": "8.0.6", "babel-plugin-dynamic-import-node": "2.3.0", "babel-plugin-syntax-jsx": "6.18.0", @@ -157,6 +156,7 @@ "ast-types": "0.13.2", "async-retry": "1.2.3", "async-sema": "3.0.0", + "autodll-webpack-plugin": "0.4.2", "chalk": "2.4.2", "ci-info": "2.0.0", "compression": "1.7.4", diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index a3180e6f427a568e2affe07c8de1b907855c09f2..e677dd998588cb2f798a1bd28640e27e75ba4d95 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -77,6 +77,15 @@ export async function ncc_async_sema(task, opts) { .target('dist/compiled/async-sema') } // eslint-disable-next-line camelcase +externals['autodll-webpack-plugin'] = + 'next/dist/compiled/autodll-webpack-plugin' +export async function ncc_autodll_webpack_plugin(task, opts) { + await task + .source(opts.src || 'build/bundles/autodll-webpack-plugin.js') + .ncc({ packageName: 'autodll-webpack-plugin', externals }) + .target('dist/compiled/autodll-webpack-plugin') +} +// eslint-disable-next-line camelcase // NB: Used by other dependencies, but Zeit version is a duplicate // version so can be inlined anyway (although may change in future) externals['chalk'] = 'next/dist/compiled/chalk' @@ -408,6 +417,7 @@ export async function precompile(task) { 'ncc_arg', 'ncc_async_retry', 'ncc_async_sema', + 'ncc_autodll_webpack_plugin', 'ncc_chalk', 'ncc_ci_info', 'ncc_compression',