Skip to content

Moved to ES module#212

Open
jbigman wants to merge 5 commits intofacundoolano:masterfrom
jbigman:main
Open

Moved to ES module#212
jbigman wants to merge 5 commits intofacundoolano:masterfrom
jbigman:main

Conversation

@jbigman
Copy link
Contributor

@jbigman jbigman commented Jan 9, 2025

And replaced request dependency by got. (same as in google-play-scrapper)

@wanghaisheng
Copy link

can i ask stupid question ,what is benefit to es module

@jbigman
Copy link
Contributor Author

jbigman commented Jan 13, 2025

Using ES (ECMAScript) modules offers several benefits, especially in modern JavaScript environments. Here are the key advantages:


1. Built-In Module Support

  • Standardized Format: ES modules (import/export) are a standardized part of JavaScript since ES6 (2015), providing a consistent syntax for modular code.
  • Native Browser Support: Modern browsers support ES modules natively without requiring bundlers or transpilers.

2. Improved Static Analysis

  • Tree Shaking: ES modules enable tools like Webpack, Rollup, or Vite to analyze code statically and remove unused exports, reducing bundle size.
  • Code Optimization: Static analysis helps with dead code elimination, leading to faster load times and better performance.

3. Explicit Dependencies

  • Clear Imports and Exports: ES modules explicitly declare dependencies using import/export syntax, improving code readability and maintainability.

4. Scope Isolation

  • Module Scope: Variables declared inside an ES module are scoped to that module, reducing the risk of global variable conflicts.

5. Asynchronous Loading

  • Dynamic Import (import()): ES modules support dynamic imports for on-demand loading, improving application performance by reducing the initial load time.
    const module = await import('./myModule.js');
    

6. Better Interoperability

  • Cross-Platform: ES modules are supported across multiple environments (browsers, Node.js, and others), ensuring consistency.
  • Future-Proofing: As part of the JavaScript standard, ES modules will continue to evolve and integrate better into modern tools and workflows.

7. Simplified Dependency Management

  • No Need for Module Wrappers: Unlike CommonJS, ES modules don’t require constructs like module.exports or require. This makes code cleaner and easier to understand.

8. Compatibility with Tools

  • Works with Modern Build Tools: ES modules are optimized for use with bundlers like Vite, Rollup, and Webpack, making them ideal for modern development workflows.
  • Backward Compatibility: Transpilers like Babel can convert ES modules into older module formats for legacy environments.

Comparison to CommonJS

Feature ES Modules CommonJS
Syntax import/export require/module.exports
Asynchronous Loading Supported Not supported
Tree Shaking Supported Not supported
Static Analysis Supported Limited
Scope Module-scoped Global scope risk
Interoperability Better in modern tools Limited to Node.js

In summary, ES modules are more performant, future-proof, and better suited to modern JavaScript development than older module systems like CommonJS.

@Jiralite
Copy link

And replaced request dependency by got.

README.md states this is a Node.js module, so why is it not using Undici? https://github.com/nodejs/undici#benchmarks

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.

3 participants