Dependency Extraction Webpack Plugin: prettify dev asset output - #79650
Dependency Extraction Webpack Plugin: prettify dev asset output#79650gunjanjaswal wants to merge 6 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @derekhassan, @xerpa43, @mattyrob. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @gunjanjaswal! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
Pretty-print PHP asset files (.asset.php / assets.php) with line breaks and indentation for unminified development builds, making the generated files human-readable. Minified production output is kept compact. The output format is keyed off `optimization.minimize`: when it is explicitly `false`, `stringify()` uses `json2php.make()` with linebreak and indent options; otherwise the compact printer is used as before. Adds unit tests for the compact/pretty branches and updates the build snapshots, which run with `minimize: false`. Fixes WordPress#48106.
5490a61 to
e882b04
Compare
…-dep-extraction-output
…-dep-extraction-output # Conflicts: # packages/dependency-extraction-webpack-plugin/test/__snapshots__/build.js.snap
…-dep-extraction-output # Conflicts: # packages/dependency-extraction-webpack-plugin/CHANGELOG.md
…-dep-extraction-output # Conflicts: # packages/dependency-extraction-webpack-plugin/CHANGELOG.md
Fixes #48106.
Right now the generated PHP asset files (
*.asset.phpandassets.php) get written all on one line, which makes something likescript-loader-packages.phpannoying to read or diff while you're working on it. This pretty-prints them on the dev (unminified) build so they're readable and diff cleanly. Production builds don't change, they still get the compact one-liner.The change lives in
stringify(): it looks atoptimization.minimize, and when that'sfalseit usesjson2php.make( { linebreak: '\n', indent: '\t' } ), otherwise it falls back to the compactjson2phpprinter exactly like before. Theminifyflag comes down fromaddAssets(), which reads it offcompilation.options.optimization.minimize.To check it, run
npm run test:unit packages/dependency-extraction-webpack-plugin, or just build a package in dev mode and open one of the generated*.asset.phpfiles. It's spread over a few indented lines now, and a production build collapses it back to one line.Use of AI Tools
This PR was written with AI assistance (Claude Code). I reviewed, tested, and understand every change, and I take responsibility for it.