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

refactor: migrate to pure es modules #2553

Merged
merged 14 commits into from
Oct 30, 2019
Merged

refactor: migrate to pure es modules #2553

merged 14 commits into from
Oct 30, 2019

Conversation

saschanaz
Copy link
Collaborator

@saschanaz saschanaz commented Oct 27, 2019

Finally some part of #2187 😄

Closes #1975

@marcoscaceres
Copy link
Contributor

Very exciting to see this!

@saschanaz saschanaz marked this pull request as ready for review October 29, 2019 07:41
@saschanaz
Copy link
Collaborator Author

The work is done, but maybe this is too big to review... 👀

src/core/xref-db.js Outdated Show resolved Hide resolved
@@ -0,0 +1,22 @@
// @ts-check
// Temporary workaround until browsers get real import-maps
Copy link
Contributor

Choose a reason for hiding this comment

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

So much sadness... but ok :)

Copy link
Contributor

Choose a reason for hiding this comment

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

What's going to be the long term strategy so we don't need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Official import maps implementation can replace this with traditional import x as "module".

copyButton.classList.add("respec-button-copy-paste", "removeOnSave");
const copyButtonPromise = createButton();

async function loadSVG() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should generalize this into a util function... loadTextAsset() or something. I imagine we eventually want to kill these methods once we address whatever is requiring them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's essentially https://github.com/w3c/respec/pull/2553#discussion_r339940372, and we can't remove it as I replied there:

No, dynamic import with dynamic value will prevent bundler from merging assets into one file, because they are not smart enough 😂

export function run() {
const cssPromise = loadStyle();

async function loadStyle() {
Copy link
Contributor

Choose a reason for hiding this comment

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

as above, loadTextAsset()?

new Blob([workerScript], { type: "application/javascript" })
);
export const worker = new Worker(workerURL);
async function loadWorkerScript() {
Copy link
Contributor

Choose a reason for hiding this comment

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

And same here... loadTextAsset(asset, path) or something.

Copy link
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

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

Pretty cool! import-maps thing is kinda sad, but 🤷🏽‍♂️... most important thing for me is that the bundles are debuggable and get automatically recompiled, the same way that webpack works. I imagine it must be the same. @saschanaz, what's the magic to get that to happen? I'd love to quickly try this out.

@marcoscaceres
Copy link
Contributor

Ok, looks like no dev server :( but that might be ok. rollup/rollup#2385 (comment)

We might be able to work around it somehow. There are a few options.

@saschanaz
Copy link
Collaborator Author

Ok, looks like no dev server :( but that might be ok. rollup/rollup#2385 (comment)

We might be able to work around it somehow. There are a few options.

Have we used webpack dev server? 👀

@marcoscaceres
Copy link
Contributor

Have we used webpack dev server? 👀

Not in this project, no (we use "serve"). But use it a lot on other projects and it's wonderful.

"release": "node ./tools/release.js",
"server": "npm start",
"snyk-protect": "snyk protect",
"snyk": "snyk",
"start": "npm run build:components && serve",
"start": "serve",
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 where the "dev server" would come in... basically, what we want here is for rollup to be watching files and automatically running babel for us.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, and also automatically building the "development" bundle.

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
Collaborator Author

Choose a reason for hiding this comment

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

We don't need babel anymore here, so you just want to refresh your browser and that's all. (Only if you are using non-built version)

@saschanaz
Copy link
Collaborator Author

what's the magic to get that to happen? I'd love to quickly try this out.

Everything should be same as before, you build the bundle and insert breakpoints 👍

@marcoscaceres
Copy link
Contributor

Ok, no babel is awesome - so that’s fantastic. But the rebuilding step is no good as it makes testing in Karma super cumbersome. That’s the last critical thing I’d really like to address. It seems it’s doable with the watch thing above.

@saschanaz
Copy link
Collaborator Author

Ok, no babel is awesome - so that’s fantastic. But the rebuilding step is no good as it makes testing in Karma super cumbersome. That’s the last critical thing I’d really like to address. It seems it’s doable with the watch thing above.

Not sure what's the rebuilding step here. If you mean builddeps, that's just a replacement of previous copydeps.

@sidvishnoi
Copy link
Member

Slightly concerned about the bundle size increase.

curl https://www.w3.org/Tools/respec/respec-w3c | wc -c                      
# 328923
$ curl https://deploy-preview-2553--respec-pr.netlify.com/respec-w3c.js | wc -c
# 389695
# +60722 bytes added

With gzip:

$ curl -H 'Accept-encoding: gzip' https://www.w3.org/Tools/respec/respec-w3c | wc -c
# 94909
$ curl -H 'Accept-encoding: gzip' https://deploy-preview-2553--respec-pr.netlify.com/respec-w3c.js | wc -c
# 121864
# +26955 bytes added

@saschanaz
Copy link
Collaborator Author

Slightly concerned about the bundle size increase.

Oops, the jquery commit did something wrong. It actually decreases without it.

@sidvishnoi
Copy link
Member

Happy with the 28043 byte reduction in size (3481 bytes in gzip) 🎉 :shipit:

@sidvishnoi
Copy link
Member

@saschanaz We still need to build:w3c before running karma, right?

@saschanaz
Copy link
Collaborator Author

@saschanaz We still need to build:w3c before running karma, right?

Right.

@marcoscaceres
Copy link
Contributor

Right, so ideally we should never need to run "build:w3c" or the other builders... the watcher should be doing that automatically for us.

@saschanaz
Copy link
Collaborator Author

That sound great, and then it sounds like an extra feature. Maybe it can be implemented after this PR?

@marcoscaceres
Copy link
Contributor

Yes, definitely could be an extra feature (and new pull request)... but what need need to confirm is that it's possible (sounds like it is, given the watcher thing) - otherwise, we will need to later switch to React.

@marcoscaceres
Copy link
Contributor

Lol, not react! webpack.

@saschanaz
Copy link
Collaborator Author

Seems there are also third-party rollup dev server libraries, so I think it should be possible to implement.

@saschanaz
Copy link
Collaborator Author

Migration to React will be even more difficult than to nanohtml 😂

@saschanaz saschanaz merged commit 24a54ca into develop Oct 30, 2019
@saschanaz saschanaz deleted the async-import branch October 30, 2019 08:23
marcoscaceres added a commit that referenced this pull request Nov 20, 2019
* develop:
  v24.34.2
  fix(tools/release): components no longer built
  chore: don't update deps
  chore(package): npm audit fixes
  Update eslint-plugin-jasmine to the latest version 🚀 (#2571)
  chore(package): update eslint-plugin-jasmine to version 3.0.0
  chore(package): update deps (#2562)
  fix(core/dfn-finder): explicit empty dfn-for on top level things (#2558)
  refactor: migrate to pure es modules (#2553)
  fix(tools/copydeps): gracely ignore when no folder (#2556)
  refactor: force extensions for imports (#2555)
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.

Migrate to webpack/rollup and ditch requirejs
3 participants