Dependency Extraction Webpack Plugin: Prettify the output of the development asset files
#48,106 建立於 2023年2月15日
描述
What problem does this address?
During the build process of WordPress the script-loader-packages.php and script-loader-packages.min.php files are generated and list the included packages, and the associated the dependencies and versions.
The unminified version is currently not formatted to be very readable by humans.
What is your proposed solution?
Since the dependency-extraction-webpack-plugin package was updated to depend on json2php 0.0.7 there is now the option to use .make() to have greater control over the formatting of the output.
I propose that the stringify() function is updated to more prettily format the output for the unminified file.
A very rough POC is to update the function to:
stringify( asset ) {
if ( this.options.outputFormat === 'php' ) {
if ( this.options.combinedOutputFile.indexOf( ".min" ) > -1 ) {
return `<?php return ${ json2php(
JSON.parse( JSON.stringify( asset ) )
) };\n`;
} else{
const printer = json2php.make( { linebreak:'\n', indent:'\t' } );
return `<?php return ${ printer(
JSON.parse( JSON.stringify( asset ) )
) };\n`;
}
}
return JSON.stringify( asset );
}
This will leave the minified file as it is currently generated but add formatting to the unminified version.