-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Switch to ES modules and Rollup #6196
Conversation
|
||
export const { | ||
deserialize | ||
} = exported; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably get rid of all instances of exporting object literals like this — I suppose this is a legacy require/codemod thing? Ideally we would always export symbols directly, and only export default for classes/functions. This makes tree-shaking more effective.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 yeah these cases were either codemod outputs (or just the quickest manual fix for the time being). I'm not sure how much tree-shaking we'll enjoy from within our codebase, since I don't think we have too much dead code within src/
... but if we do end up going the code-splitting route, this could make a notable difference in the worker blob size. It'll also just be simpler/clearer code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you ticket this as a followup item?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, already did: #6293
@@ -1,5 +1,5 @@ | |||
/* eslint-disable */ | |||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | |||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw (f.code="MODULE_NOT_FOUND", f)}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committed accidentally?
bench/unit/bench_transform.js
Outdated
}).on('cycle', (event) => { | ||
console.log(String(event.target)); | ||
|
||
}).run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove those benchmarks as a part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can reinstate them or remove them in a separate PR -- I was just getting distracted by the error messages coming from these files :)
build/generate-struct-arrays.js
Outdated
const fs = require('fs'); | ||
|
||
require = require('@std/esm')(module, {"cjs":true, "esm":"js"}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on why flow-remove-types
and @std/esm
don't play well together? It would be great if we could avoid generating the source to a separate src_untyped
folder...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some context here: standard-things/esm#119
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if we could avoid generating the source to a separate src_untyped folder...
I agree, I'm really hoping we can avoid a build step for tests 🤞
16dc3fa
to
b453261
Compare
6fa5bec
to
4a30c29
Compare
BTW how's the total bundle size (minified/gzipped) looking? |
@mourner pretty good! master
rollup-anandthakker
|
87de8c6
to
e035847
Compare
Alright, using Rollup's relatively new code splitting feature, we're now at a point where we have a smaller bundle that loads as fast as our browserify build. Before I embark on the longish tail of tasks that would be needed to finish this and merge it into The advantages:
The disadvantages:
@mapbox/gl-core what do you think? Please weigh in! It's definitely not too late to abandon this effort if we don't feel that the time is right. |
I can't really comment on the overall approach although it sounds like progress! Two questions:
|
I think this is the most important unanswered question. Way back in the day we reverted an early attempt to introduce ES6 syntax because tooling wasn't ready -- specifically debuggers and code coverage. I rely on running individual test files pretty frequently, often attaching a node debugger to track down test failures. If switching to ES6 modules would mean I can no longer do that, I'd prefer to hold off on it. |
e035847
to
e9eb4a6
Compare
🎉 looks like |
Another open question: how should we build the benchmarks? Options:
I was initially thinking that another downside to option 2 is that it would preclude being able to benchmark anything that included worker load time, because we'd be loading the worker in a different manner than in the shipped library. But in fact, I don't think it would really be practical to measure this within our benchmarking system regardless of how we load the workers, so I don't think this should be a factor. |
f2912dc
to
28880a9
Compare
@ChrisLoer I haven't dug into the details here, but I think dynamic imports might indeed make this a possibility. (But we'd likely have to also have to keep supporting the existing approach for the foreseeable future.)
Not much more than what's documented in #5939 -- I'll do another pass at this again soon, along with running our normal benchmarks, and post results here. |
yarn.lock
Outdated
dependencies: | ||
chalk "~0.4.0" | ||
underscore "~1.6.0" | ||
version "2.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this to fix the build (zaach/jsonlint#103 (comment)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally I think this is great, and we should move forward. It's a bit scary for sure, but ultimately feels like the right choice for future.
Apart from the remaining bullet points and making the build green, I'd love to add a bunch of eslint-plugin-import rules to our ESLint config — used this plugin and it is fantastic. Can help catch a lot of subtle bugs.
Also, would be great to fix a few remaining export const exported = { ... }
cases, but I'm fine with leaving it for a follow-up PR if it makes it easier to ship.
5to6 cjs transform
Specifically for zaach/jsonlint#103 (comment)
- Remove browserify - Update build tests
ef1b40d
to
98833b9
Compare
Closes #5939
Refs #6056
This PR:
Note on building the Worker bundle blob:
There's a substantial change here in our approach to constructing the
Blob
URL for the worker script, becausewebworkify
depends on specificbrowserify
implementation details. The way we're doing it now:src/index.js
andsrc/source/worker.js
. The result is three bundles:rollup/build/index.js
,rollup/build/worker.js
, androllup/build/chunk1.js
. The first two correspond to the two entrypoints, and the third consists of all the code that is shared by the main thread and worker scripts.Note on running our code in Node:
In order to run our Flow-annotated ES module code in a Node environment, we have to use two
require
hooks. Previously, we would do this for flow by doingrequire('flow-remove-types/register')
in our common unit test module -- this allowed us torequire
flow-annotated files from tests, but did not permit flow in the test files themselves. Instead, we're now tellingnode
to requireflow-remove-types
(and@std/esm
, for modules) directly via command-line arguments; you can runnode
ortap
with these args already set using thebuild/run-{tap,node}
scripts.Benchmarks
Full
Re-run of Paint
Time to first render:
rollup-anandthakker:
master
Minified bundle size:
Todo
Check whether "minifying" the style-spec (as in https://github.com/mapbox/mapbox-gl-js/blob/master/build/minifyify_style_spec.js) eliminates the perf regression in the worker-gets-the-whole-bundle approachNOPE.access_token_generated.js
)const exported = {...}; export default exported;
) -- ticketed Replace exported objects with named exports #6293