axios-shadow

wrapper for axios to code splitting

Usage no npm install needed!

<script type="module">
  import axiosShadow from 'https://cdn.skypack.dev/axios-shadow';
</script>

README

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