-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
mmdparser: Convert to ES6 classes. #26935
Conversation
Yeah, not sure if modifing a built lib directly is the right approach, often it's copy-pasted from the source repo: It would be problematic on next updates. Maybe better to take the npm + unpkg.com route. |
I've had to vendor some in |
Also not sure how you're testing this, but MMDParser is tree-shakeable in my tests for esbuild, webpack and rollup. Here is the test I did: // node_modules/three/examples/jsm/loaders/MMDLoader.js
import { Loader } from 'three';
import { MMDParser } from '../libs/mmdparser.module.js';
class MMDLoader extends Loader {
_getParser() {
if ( this.parser === null ) {
this.parser = new MMDParser.Parser();
}
return this.parser;
}
}
class UsedClass {}
export { MMDLoader, UsedClass }; // src/index.js
import { UsedClass } from 'three/addons/loaders/MMDLoader.js';
console.log(UsedClass) With all bundlers only the UsedClass is present in the final bundler. |
I've been testing with Perhaps this isn't good enough. Prior, I setup https://github.com/CodyJasonBennett/treeshaking to test misc. behaviors. |
I would like to continue to copy libs into the repository. Not all developers use Besides, certain libs perform too much logging or inconsistent error handling that contradicts
Looking back at 8 years of maintenance, upgrading third party libs was never an issue. The copy is fast, formatting happens automatically if wanted, and the number of third party libs is small. Besides, we never blindly upgrade dependencies and there is no pressure to upgrade to each patch or minor release. |
We can continue packaging them, but why we couldn't use, for example, external |
@CodyJasonBennett hmmm not sure about the inner workings of that tool, it is better to test with the bundler directly in my opinion. I have setup a repo similar to yours if it's useful, with esbuild + rollup + webpack. Make sure to import from the |
@LeviPesin We can solve the tree-shaking issues without changing the policy how external libraries are managed. |
I'll leave it to @takahirox as for whether this is preferable for code-style or other reasons, but for tree-shaking this PR proves unneeded and comically difficult to review. Thanks @marcofugaro for the assistance and direction. |
@takahirox should we update the mmd examples to user the |
Regarding ES6, Regarding npm or unpkg, I think it should be aligned with our external libs policy. If other libs are imported via npm/unpkg, |
Related issue: #XXXX
Description
Converts the mmdparser lib to ES6 modules for tree-shaking. This was wrapped in an IIFE in #26912, but is otherwise not very complicated to refactor compared to other libs. There is a remaining lint warning for the use of
throw 'str'
instead ofthrow new Error( 'str' )
that I've left untouched.