提交 40f6bdef 编写于 作者: G Guy Bedford 提交者: Joe Haddad

autodll-webpack-plugin

上级 8b1ea308
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')
}
......@@ -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',
......
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
}
......@@ -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",
......
......@@ -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',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册