Native ES Modules in Browsers (Without Bundlers)
If you want to use lunex-http
directly in modern browsers without a bundler, you can import it from an ESM CDN like esm.sh. This approach leverages native ES module support in browsers.
Usage Example
Create a JavaScript module (e.g., main.js
) with the following import:
import LunexClient from 'https://esm.sh/lunex-http';
const client = new LunexClient('https://api.example.com', {
Authorization: 'Bearer YOUR_TOKEN'
});
Include your script in your HTML with the type="module" attribute:
<script type="module" src="main.js"></script>
Notes
- Native ES modules in browsers do not support bare module specifiers like 'lunex-http'. You must use a full URL to an ESM CDN.
- Ensure you are targeting modern browsers that support ES modules (most modern browsers do).
- Performance might be lower compared to bundling, due to on-demand fetching of dependencies.
- For production, bundling remains the recommended approach for better caching and optimization.
Troubleshooting
- If you get errors like Failed to resolve module specifier, double-check your import URL is correct.
- Network issues with the CDN can affect loading; consider caching strategies or bundling for critical apps.