forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bypass webpack compilation for precompiled @next/polyfills-nomodule
Removes the extra webpack handling that was previously done, this ensures the file which is already minified and compiled does not get passed through minification again. Largely based on vercel#21418 Closes vercel#21418 Co-Authored-By: Joe Haddad <[email protected]>
- Loading branch information
1 parent
c63bfbe
commit 6a2c79d
Showing
5 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { promises as fs } from 'fs' | ||
import loaderUtils from 'next/dist/compiled/loader-utils' | ||
import { | ||
isWebpack5, | ||
sources, | ||
webpack, | ||
} from 'next/dist/compiled/webpack/webpack' | ||
|
||
const PLUGIN_NAME = 'CopyFilePlugin' | ||
|
||
export class CopyFilePlugin { | ||
private source: string | ||
private name: string | ||
private minimize: boolean | ||
private info?: object | ||
|
||
constructor({ | ||
source, | ||
name, | ||
minimize, | ||
info, | ||
}: { | ||
source: string | ||
name: string | ||
minimize: boolean | ||
info?: object | ||
}) { | ||
this.source = source | ||
this.name = name | ||
this.minimize = minimize | ||
this.info = info | ||
} | ||
|
||
apply(compiler: webpack.Compiler) { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { | ||
const hook = isWebpack5 | ||
? // @ts-ignore | ||
compilation.hooks.processAssets | ||
: compilation.hooks.additionalAssets | ||
hook.tapPromise( | ||
isWebpack5 | ||
? { | ||
name: PLUGIN_NAME, | ||
// @ts-ignore TODO: Remove ignore when webpack 5 is stable | ||
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, | ||
} | ||
: PLUGIN_NAME, | ||
async () => { | ||
const content = await fs.readFile(this.source, 'utf8') | ||
|
||
const file = loaderUtils.interpolateName( | ||
{ resourcePath: this.source }, | ||
this.name, | ||
{ content, context: compiler.context } | ||
) | ||
|
||
// @ts-ignore | ||
compilation.emitAsset(file, new sources.RawSource(content), { | ||
...this.info, | ||
}) | ||
} | ||
) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters