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

Use Babel and ES6 in docs JS files #31607

Merged
merged 11 commits into from
Apr 12, 2022
Merged

Use Babel and ES6 in docs JS files #31607

merged 11 commits into from
Apr 12, 2022

Conversation

NotWoods
Copy link
Contributor

@NotWoods NotWoods commented Sep 6, 2020

Fixes #30818

Updates the assets/js path inside of site so that the code is passed through Babel, using the root Babel RC file.

Additionally adds a ESLint config in the assets folder to enable a higher ecma version, but only for doc files.


I didn't pass extra_js scripts through Babel, since the equivalent extra_css scripts in the Examples folder don't get processed. I can add this if desired.

Preview: https://deploy-preview-31607--twbs-bootstrap.netlify.app/

TODO:

  • Revisit if we need babel after all
  • Array.from instead of Array.prototype.slice.call
  • Look into inheriting from root .eslintrc.json

@NotWoods NotWoods requested a review from a team as a code owner September 6, 2020 05:03
@XhmikosR
Copy link
Member

XhmikosR commented Sep 8, 2020 via email

@NotWoods
Copy link
Contributor Author

NotWoods commented Sep 8, 2020

I didn't realize adding imports was one of the goals, I'll take another look and see how Hugo's bundler works. I didn't mean to change the root eslint file but the subfile is nessecary.

Copy link
Member

@XhmikosR XhmikosR left a comment

Choose a reason for hiding this comment

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

babel should only run for our files and not all files

})
}
const exampleModal = document.getElementById('exampleModal')
exampleModal?.addEventListener('show.bs.modal', event => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you revert the optional chaining changes and revert the .eslintrc.json change? We don't use optional chaining anywhere else right now and I'd like to be consistent.

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 I remove the eslint file, the linter will complain about any ES6 syntax (i.e. const). It's set up to only affect files in the docs folder.

I'll revert the optional chains.

Copy link
Member

Choose a reason for hiding this comment

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

NVM about the comment regarding the ESLint changes. Your changes are good since we have an upper eslintrc.json in site folder because the examples still use ES5.

@XhmikosR
Copy link
Member

@regisphilibert: how does this implementation look good to you? Is there any other way to achieve the same result without the temp file?

Also, thanks @NotWoods for sticking with us, every thing to improve things is welcome :)

@XhmikosR
Copy link
Member

@Johann-S what do you think about this?

My concerns are:

  1. it slows down the build a lot, but I suppose it's bearable
  2. we don't use imports

I wonder if we could use esbuild later which should be a lot faster.

@Johann-S
Copy link
Member

It seems ok to me, but yes we can import our source code that's possible too, but it'll produce a bigger js file and we won't use the Bootstrap CDN

@XhmikosR
Copy link
Member

We don't use a CDN for our docs :)

@XhmikosR XhmikosR removed this from Inbox in v5.0.0-beta1 Nov 25, 2020
@XhmikosR XhmikosR added this to Inbox in v5.0.0-beta2 via automation Nov 25, 2020
@XhmikosR XhmikosR moved this from Inbox to Review in v5.0.0-beta2 Nov 25, 2020
@XhmikosR XhmikosR removed this from Review in v5.0.0-beta2 Dec 14, 2020
@XhmikosR XhmikosR added this to Inbox in v5.0.0-beta3 via automation Dec 14, 2020
@mdo
Copy link
Member

mdo commented Feb 11, 2021

Still worth finishing off @XhmikosR?

@XhmikosR
Copy link
Member

I'll need to rebase the branch since it has conflicts.

That being said, it's the wise thing to make things consistent with code. The only downside I see is that this slows down the build, hence why I've left the PR hanging.

But I'll take another stab at it in the next days.

@XhmikosR XhmikosR added this to Inbox in v5.0.0 via automation Mar 2, 2021
@XhmikosR XhmikosR removed this from Inbox in v5.0.0-beta3 Mar 2, 2021
@XhmikosR XhmikosR moved this from In progress to To do in v5.2.0 Sep 7, 2021
@XhmikosR XhmikosR force-pushed the babel branch 6 times, most recently from ced555c to 5168a3d Compare March 11, 2022 15:58
@XhmikosR XhmikosR changed the title Use Babel and ES6 in documentation Use Babel and ES6 in docs JS files Mar 11, 2022
@XhmikosR XhmikosR moved this from To do to Review in progress in v5.2.0 Mar 11, 2022
@GeoSot
Copy link
Member

GeoSot commented Mar 12, 2022

I think we can use NodeList.prototype.forEach() in place of Array.from

https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#browser_compatibility

@GeoSot
Copy link
Member

GeoSot commented Apr 7, 2022

/CC @XhmikosR any opinion over this?

I think we can use NodeList.prototype.forEach() in place of Array.from

I think it's the last thing in order to merge

@mdo
Copy link
Member

mdo commented Apr 11, 2022

@GeoSot Want to wait for that change, or merge this and make it in another PR?

@GeoSot
Copy link
Member

GeoSot commented Apr 12, 2022

@mdo Better merge it . It is too minor to keep us down

@XhmikosR XhmikosR merged commit fe25782 into twbs:main Apr 12, 2022
v5.2.0 automation moved this from Review in progress to Done Apr 12, 2022
@mdo mdo mentioned this pull request May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v5.2.0
  
Done
Development

Successfully merging this pull request may close these issues.

docs v5: switch to ES6
5 participants