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

Fix minified dist bundles #1094

Merged
merged 5 commits into from
Oct 27, 2016
Merged

Fix minified dist bundles #1094

merged 5 commits into from
Oct 27, 2016

Conversation

etpinard
Copy link
Contributor

The ugly webworkify + Require.js bug strikes again 👻 The 1.19.0 dist builds are broken in Require.js. In #914 (more specifically #914 (comment)) I chose to run the plotly.min.js + require.js test only on the main dist bundle because minifying plotly.js takes about 1 minute. That is, it was testing new code only on release builds (like this one).

BUT, I should add: minifying plotly.js take about 1 minute, that's using node.js v4. Using node.js v6, the minifying time drops to about ~30 seconds. Good enough for me. Let's test this thing on every build!

- bumping to node v6 disrupted the "a(r)" assumption
- so that both bundle.js and cibundle.js can use it.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
- so that require.js test can be properly ran on
  each build!
@etpinard etpinard added bug something broken type: maintenance labels Oct 27, 2016
var strOld = FRONT + MIDDLE + BACK,
strNew = FRONT + ' ' + MIDDLE + ' ' + BACK;

minifiedCode = minifiedCode.replace(strOld, strNew);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if there's a way to do using Regex, please let me know!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rreusser 's got the answer

minifiedCod.replace(/require\("\+(\w)\((\w)\)\+"\)/, 'require("+ $1($2) +")')

Copy link
Contributor

Choose a reason for hiding this comment

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

It could also be done using .split(strOld).join(strNew) but I have no idea if it would be any faster in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@rreusser rreusser Oct 27, 2016

Choose a reason for hiding this comment

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

A slight modification for lower or uppercase:

/require\("\+([A-z])\(([A-z])\)\+"\)/

Copy link
Contributor

Choose a reason for hiding this comment

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

I counter with https://regex101.com/

Copy link
Contributor

@mdtusz mdtusz left a comment

Choose a reason for hiding this comment

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

Lgtm so long as we're happy with only lowercase.

💃

}
}

return minifiedCode;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is hilarious. Do we need to check for uppercase letters or does it stick to all lowers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Does uglify-js use uppercase lettes? I don't know. But anyway, @rreusser's solution should cover that case too.

Copy link
Contributor

@rreusser rreusser Oct 27, 2016

Choose a reason for hiding this comment

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

I always forget the semantics of A-z vs. \W vs. \w. Okay:

  • \w: Matches any alphanumeric character including the underscore. Equivalent to [A-Za-z0-9_].
  • \W: Matches any non-word character. Equivalent to [^A-Za-z0-9_]. (= negation)
  • [A-Za-z] any lower or uppercase character
  • [A-z] maybe the same?

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
*
*/
module.exports = function patchMinified(minifiedCode) {
return minifiedCode.replace(STR_TO_REPLACE, STR_NEW);
return minifiedCode.replace(PATTERN, NEW_SUBSTR);
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@etpinard etpinard merged commit 019fbcb into master Oct 27, 2016
@etpinard etpinard deleted the fix-dist branch October 27, 2016 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants