Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line breaks to precompiled schemas so that git can merge changes in the output #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Knagis
Copy link

@Knagis Knagis commented Dec 22, 2021

Currently the output is a single line which means at every single change in the WebpackOptions.check.js file is a conflict and needs manual rebase.

This PR applies prettier to the minified output, resulting in still mangled code, but split in lines that git should be able to handle.

image

@Knagis
Copy link
Author

Knagis commented Jan 18, 2022

@sokra could you please take a look at this? it should reduce how frequently PR rebases are needed in webpack.

@sokra
Copy link
Member

sokra commented Nov 9, 2022

For performance reasons this is a minimized file. Adding prettier would increase the file size a lot...

@Knagis
Copy link
Author

Knagis commented Nov 9, 2022

Tested (this time more likely accurately) - 5.69.0 version size increased from 218KB to 283KB

@Knagis
Copy link
Author

Knagis commented Nov 9, 2022

sadly terser does not export its output formatting code (which is why i originally went with prettier), so this requires bit of a hack:

	// minimize
	const ast = (
		await terser.minify(code, {
			compress: {
				passes: 3,
			},
			format: {
				ast: true,
				code: false,
			},
			mangle: true,
			ecma: 2015,
			toplevel: true,
		})
	).ast;

	const real_print = ast.print;
	ast.print = (output, ...args) => {
		const real_with_block = output.with_block;
		output.with_block = (...args) => {
			real_with_block.call(output, ...args);
			output.print("\n");
		};
		return real_print.call(ast, output, ...args);
	};
	code = ast.print_to_string({ ecma: 2015 });

With this it is possible to get nice "formatting" with just 6KB increase

image

my intent was to avoid new dependencies for the package, so only terser and prettier are available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants