https://github.com/wmzy/axios-shadow
A wrapper for axios to code splitting.
https://github.com/wmzy/axios-shadow
axios code-splitting
Last synced: 11 months ago
JSON representation
A wrapper for axios to code splitting.
- Host: GitHub
- URL: https://github.com/wmzy/axios-shadow
- Owner: wmzy
- Created: 2019-09-16T11:02:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T10:27:55.000Z (about 3 years ago)
- Last Synced: 2024-10-02T09:18:35.847Z (over 1 year ago)
- Topics: axios, code-splitting
- Language: JavaScript
- Homepage:
- Size: 547 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/wmzy/axios-shadow)
[](https://coveralls.io/github/wmzy/axios-shadow?branch=master)
# axios-shadow
> A wrapper for axios to code splitting.
## Installation
```bash
npm i axios-shadow
```
## Usage
### Init with a splitting axios
With [dynamic imports](https://webpack.js.org/guides/code-splitting/#dynamic-imports) we can split `axios` from the main bundle.
```js
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
```js
// 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
```js
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](.broserslistrc) with [these methods or APIs](.eslintrc.js#L27) pollyfilled.
## Workflow
```bash
# develop
npm start
# build
npm run build
# test
npm test
# commit changes
npm run commit
# publish
npm publish
```