Browser Usage with Bundlers
If you are building web applications using bundlers like Vite, Webpack, or Rollup, you can install and import lunex-http
as a module. Your bundler will handle packaging the library for browser compatibility.
Using npm
npm install lunex-http
Using Yarn
yarn add lunex-http
Using pnpm
pnpm add lunex-http
Once installed, import and use the client in your JavaScript or TypeScript code:
import LunexClient from 'lunex-http';
const client = new LunexClient('https://api.example.com', {
Authorization: 'Bearer YOUR_TOKEN'
});
This approach is recommended for React, Vue, Angular, or other modern frontend projects using bundlers. It ensures optimized builds, efficient module resolution, and compatibility with browser environments.
Benefits of Using Bundlers
- Optimized builds: Minification, tree shaking, and bundling reduce your final bundle size.
- Cache management: Bundlers help manage caching strategies to improve app performance.
- Module resolution: Handles third-party package resolution and compatibility for browser targets.
- Source maps: Easier debugging with proper source mapping.
Troubleshooting
- If you encounter errors like Cannot find module 'lunex-http' or similar, ensure that your bundler is configured to resolve node_modules correctly.
- Make sure your environment supports ES modules or your bundler transpiles accordingly.
- If using TypeScript, no additional typings installation is required since lunex-http includes full TypeScript support.