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

core(build): add js minification to inline-fs plugin #13272

Merged
merged 1 commit into from
Oct 27, 2021

Conversation

brendankenny
Copy link
Member

@brendankenny brendankenny commented Oct 27, 2021

part of #13231

just uses our current settings (default terser minification targeting ecma: 2019).

@brendankenny brendankenny requested a review from a team as a code owner October 27, 2021 16:48
@brendankenny brendankenny requested review from connorjclark and removed request for a team October 27, 2021 16:48
@google-cla google-cla bot added the cla: yes label Oct 27, 2021

// TODO(bckenny): minify inlined javascript.
// Minify inlined javascript.
if (constructedPath.endsWith('.js')) {
Copy link
Member Author

@brendankenny brendankenny Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One notable thing is that our current pipeline (and now this plugin) spends a full 2 seconds on my machine trying to re-minify axe.min.js, which ends up saving about 1.9KB (out of 416KB for just that file), much of which ends up being from stripping the license header out :)

We could skip minifying when constructedPath.endsWith('.min.js'), but not sure what balance is there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the license remain? https://github.com/terser/terser#:~:text=JSDoc-style%20comments-,that%20contain%20%22%40license%22,-%2C%20%22%40preserve%22%20or%20start

No strong preference here. Keeping the extra minification pass seems fine to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, it starts with /*! so it is actually preserved.

It's mostly annoying just how slow that single file is compared to everything else, but I'm fine keeping the status quo of not special casing it

Comment on lines +370 to +373
// Verify that minification was valid. End result should be something like:
// `const sum = eval('function add(a,b){return a+b}add(1,2);')sum;`
const evaledResult = eval(code);
expect(evaledResult).toEqual(3);
Copy link
Member Author

@brendankenny brendankenny Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is kind of tricky code but it should be robust to future changes to minification tool and options, and it didn't feel right to not have any unit test that the inlined string was still evaluatable javascript

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

Successfully merging this pull request may close these issues.

3 participants