axios-shadow

0.1.3 • Public • Published

Build Status Coverage Status

axios-shadow

A wrapper for axios to code splitting.

Installation

npm i axios-shadow

Usage

Init with a splitting axios

With dynamic imports we can split axios from the main bundle.

import axios from 'axios-shadow';

axios.getModule = () => import('axios');
// or
axios.getInstance = () => import('axios').then(({default: axios}) => {
  // you can init global axios defaults and interceptors
  axios.defaults.baseURL = 'https://api.example.com';
  // ...

  // custom instance also support
  // return axios.create();
  return axios;
});

Use a shadow instance

// axios.js
import {create} from 'axios-shadow';

const axios = create();

axios.getInstance = () => import('axios').then(m => m.default.create());

export default axios;

Use axios shadow for request

import axios from 'axios-shadow';
// or
import axios from './axios';

// all async methods are proxied
axios(url).then(response => {});
axios.get(url).then(response => {});

Compatibility Note

This lib support these browsers or devices with these methods or APIs pollyfilled.

Workflow

# develop
npm start

# build
npm run build

# test
npm test

# commit changes
npm run commit

# publish
npm publish

Readme

Keywords

Package Sidebar

Install

npm i axios-shadow

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

15.4 kB

Total Files

10

Last publish

Collaborators

  • wmzy