@wordpress/dependency-extraction-webpack-plugin
Advanced tools
Comparing version 3.2.2-next.5df0cd52b7.0 to 3.2.3-next.33ec3857e2.0
@@ -5,2 +5,6 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. --> | ||
## 3.2.2-next.0 (2021-12-20) | ||
- Add the optional `externalizedReportFile` option ([#35106](https://github.com/WordPress/gutenberg/pull/35106)). | ||
## 3.0.0 (2021-01-21) | ||
@@ -7,0 +11,0 @@ |
@@ -20,2 +20,4 @@ /** | ||
const defaultExternalizedReportFileName = 'externalized-dependencies.json'; | ||
class DependencyExtractionWebpackPlugin { | ||
@@ -27,4 +29,6 @@ constructor( options ) { | ||
combinedOutputFile: null, | ||
externalizedReport: false, | ||
injectPolyfill: false, | ||
outputFormat: 'php', | ||
outputFilename: null, | ||
useDefaults: true, | ||
@@ -142,6 +146,22 @@ }, | ||
combinedOutputFile, | ||
externalizedReport, | ||
injectPolyfill, | ||
outputFormat, | ||
outputFilename, | ||
} = this.options; | ||
// Dump actually externalized dependencies to a report file. | ||
if ( externalizedReport ) { | ||
const externalizedReportFile = | ||
typeof externalizedReport === 'string' | ||
? externalizedReport | ||
: defaultExternalizedReportFileName; | ||
compilation.emitAsset( | ||
externalizedReportFile, | ||
new RawSource( | ||
JSON.stringify( Array.from( this.externalizedDeps ).sort() ) | ||
) | ||
); | ||
} | ||
const combinedAssetsData = {}; | ||
@@ -184,3 +204,5 @@ | ||
const runtimeChunk = entrypoint.getRuntimeChunk(); | ||
const entrypointChunk = isWebpack4 | ||
? entrypoint.chunks.find( ( c ) => c.name === entrypointName ) | ||
: entrypoint.getEntrypointChunk(); | ||
@@ -190,3 +212,3 @@ const assetData = { | ||
dependencies: Array.from( entrypointExternalizedWpDeps ).sort(), | ||
version: runtimeChunk.hash, | ||
version: entrypointChunk.hash, | ||
}; | ||
@@ -201,3 +223,3 @@ | ||
{ | ||
chunk: runtimeChunk, | ||
chunk: entrypointChunk, | ||
filename, | ||
@@ -217,10 +239,26 @@ query, | ||
const assetFilename = buildFilename.replace( | ||
/\.js$/i, | ||
'.asset.' + ( outputFormat === 'php' ? 'php' : 'json' ) | ||
); | ||
let assetFilename; | ||
if ( outputFilename ) { | ||
assetFilename = compilation.getPath( outputFilename, { | ||
chunk: entrypointChunk, | ||
filename, | ||
query, | ||
basename: basename( filename ), | ||
contentHash: createHash( 'md4' ) | ||
.update( assetString ) | ||
.digest( 'hex' ), | ||
} ); | ||
} else { | ||
assetFilename = buildFilename.replace( | ||
/\.js$/i, | ||
'.asset.' + ( outputFormat === 'php' ? 'php' : 'json' ) | ||
); | ||
} | ||
// Add source and file into compilation for webpack to output. | ||
compilation.assets[ assetFilename ] = new RawSource( assetString ); | ||
runtimeChunk.files[ isWebpack4 ? 'push' : 'add' ]( assetFilename ); | ||
entrypointChunk.files[ isWebpack4 ? 'push' : 'add' ]( | ||
assetFilename | ||
); | ||
} | ||
@@ -227,0 +265,0 @@ |
@@ -14,2 +14,3 @@ import { Compiler } from 'webpack'; | ||
outputFormat?: 'php' | 'json'; | ||
outputFilename?: string | Function, | ||
requestToExternal?: ( request: string ) => string | string[] | undefined; | ||
@@ -19,2 +20,3 @@ requestToHandle?: ( request: string ) => string | undefined; | ||
combineAssets?: boolean; | ||
externalizedReportFile?: string | undefined; | ||
} |
@@ -37,2 +37,6 @@ const WORDPRESS_NAMESPACE = '@wordpress/'; | ||
if ( request.includes( 'react-refresh/runtime' ) ) { | ||
return 'ReactRefreshRuntime'; | ||
} | ||
if ( BUNDLED_PACKAGES.includes( request ) ) { | ||
@@ -70,2 +74,6 @@ return undefined; | ||
if ( request.includes( 'react-refresh/runtime' ) ) { | ||
return 'wp-react-refresh-runtime'; | ||
} | ||
if ( request.startsWith( WORDPRESS_NAMESPACE ) ) { | ||
@@ -72,0 +80,0 @@ return 'wp-' + request.substring( WORDPRESS_NAMESPACE.length ); |
{ | ||
"name": "@wordpress/dependency-extraction-webpack-plugin", | ||
"version": "3.2.2-next.5df0cd52b7.0", | ||
"version": "3.2.3-next.33ec3857e2.0", | ||
"description": "Extract WordPress script dependencies from webpack bundles.", | ||
@@ -33,3 +33,3 @@ "author": "The WordPress Contributors", | ||
"json2php": "^0.0.4", | ||
"webpack-sources": "^2.2.0" | ||
"webpack-sources": "^3.2.2" | ||
}, | ||
@@ -42,3 +42,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "558d577d12bec15f05e694eb49a094836d885cca" | ||
"gitHead": "51c7917ea7fac72953702f24d6daac87d99e7617" | ||
} |
@@ -110,2 +110,9 @@ # Dependency Extraction Webpack Plugin | ||
##### `outputFilename` | ||
- Type: string | function | ||
- Default: null | ||
The filename for the generated asset file. Accepts the same values as the Webpack `output.filename` option. | ||
##### `combineAssets` | ||
@@ -139,2 +146,10 @@ | ||
##### `externalizedReport` | ||
- Type: boolean | string | ||
- Default: `false` | ||
Report all externalized dependencies as an array in JSON format. It could be used for further manual or automated inspection. | ||
You can provide a filename, or set it to `true` to report to a default `externalized-dependencies.json`. | ||
##### `requestToExternal` | ||
@@ -141,0 +156,0 @@ |
59668
362
237
+ Added@types/node@22.13.4(transitive)
+ Addedelectron-to-chromium@1.5.101(transitive)
+ Addedterser@5.39.0(transitive)
+ Addedwebpack@5.98.0(transitive)
- Removed@types/node@22.13.1(transitive)
- Removedajv@6.12.6(transitive)
- Removedajv-keywords@3.5.2(transitive)
- Removedelectron-to-chromium@1.5.97(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedschema-utils@3.3.0(transitive)
- Removedsource-list-map@2.0.1(transitive)
- Removedterser@5.38.2(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedwebpack@5.97.1(transitive)
- Removedwebpack-sources@2.3.1(transitive)
Updatedwebpack-sources@^3.2.2