mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
chore: bundles exports everything and webpack bundles everything
This commit is contained in:
parent
79ce1926d2
commit
ed1e163472
@ -1,9 +1,8 @@
|
||||
# Compiled code
|
||||
|
||||
## NodeJS
|
||||
## CommonJS
|
||||
|
||||
The code is compiled with `tsc` with support to `>= ES6`. See the
|
||||
[build config](/tsconfig.build.json).
|
||||
The code is compiled with `webpack` for ES2017+.
|
||||
|
||||
- `axios-cache-interceptor`: Redirects to `/dist/index.js`
|
||||
- `axios-cache-interceptor/dist/index.js`: The main library file.
|
||||
@ -12,7 +11,7 @@ The code is compiled with `tsc` with support to `>= ES6`. See the
|
||||
Every browser build is also compatible with CommonsJS because it builds with UMD, so you
|
||||
can use them too.
|
||||
|
||||
## Browsers
|
||||
## UMD
|
||||
|
||||
> _NOTE_: Axios itself requires [ES6 Promises](https://axios-http.com/docs/notes#promises)
|
||||
|
||||
@ -23,7 +22,7 @@ CommonsJS and more)
|
||||
- `axios-cache-interceptor/dist/index.min.js`: Production file for ES6+
|
||||
- `axios-cache-interceptor/dist/index.es5.min.js`: Production file for ES5+
|
||||
- `axios-cache-interceptor/dist/index.es2020.min.js`: Production file for ES2020+
|
||||
- `axios-cache-interceptor/dist/index.development.js`: Development file
|
||||
- `axios-cache-interceptor/dist/index.development.js`: Development file (ES2020+)
|
||||
|
||||
```html
|
||||
<!-- You can use the cdn of your choice -->
|
||||
|
||||
@ -2,17 +2,16 @@
|
||||
"name": "axios-cache-interceptor",
|
||||
"version": "0.7.9",
|
||||
"description": "Cache interceptor for axios",
|
||||
"types": "./dist/index.ts",
|
||||
"main": "./dist/index.js",
|
||||
"browser": "./dist/index.min.js",
|
||||
"jsdelivr": "./dist/index.min.js",
|
||||
"unpkg": "./dist/index.min.js",
|
||||
"runkitExampleFilename": "./examples/runkit.js",
|
||||
"scripts": {
|
||||
"build": "concurrently 'npm:build:*'",
|
||||
"build:browser": "webpack",
|
||||
"build:node": "tsc -p tsconfig.build.json",
|
||||
"build": "webpack",
|
||||
"test": "jest --coverage",
|
||||
"escheck": "es-check es5 ./dist/index.es5.min.js && es-check es6 ./dist/index.min.js",
|
||||
"escheck": "npx es-check es5 ./dist/index.es5.min.js && npx es-check es6 ./dist/index.min.js",
|
||||
"format": "prettier --write .",
|
||||
"lint": "tsc --noEmit && eslint . --ext .ts",
|
||||
"version": "auto-changelog -p && git add CHANGELOG.md"
|
||||
@ -53,8 +52,6 @@
|
||||
"@typescript-eslint/parser": "^5.8.1",
|
||||
"auto-changelog": "^2.3.0",
|
||||
"axios": "~0.24.0",
|
||||
"concurrently": "^7.0.0",
|
||||
"es-check": "^6.1.1",
|
||||
"eslint": "^8.3.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
|
||||
2
src/cache/create.ts
vendored
2
src/cache/create.ts
vendored
@ -1,8 +1,8 @@
|
||||
import type { AxiosInstance } from 'axios';
|
||||
import { isStorage } from '..';
|
||||
import { defaultHeaderInterpreter } from '../header/interpreter';
|
||||
import { CacheRequestInterceptor } from '../interceptors/request';
|
||||
import { CacheResponseInterceptor } from '../interceptors/response';
|
||||
import { isStorage } from '../storage/build';
|
||||
import { buildMemoryStorage } from '../storage/memory';
|
||||
import { defaultKeyGenerator } from '../util/key-generator';
|
||||
import type { AxiosCacheInstance } from './axios';
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
/** Index file for webpack and cdn usage */
|
||||
|
||||
export {
|
||||
createCache,
|
||||
isAxiosCacheInterceptor,
|
||||
setupCache,
|
||||
useCache
|
||||
} from './cache/create';
|
||||
export { buildStorage } from './storage/build';
|
||||
export { buildMemoryStorage } from './storage/memory';
|
||||
export { buildWebStorage } from './storage/web-api';
|
||||
@ -1,15 +1,5 @@
|
||||
/** Index file for webpack and cdn usage */
|
||||
|
||||
export {
|
||||
createCache,
|
||||
isAxiosCacheInterceptor,
|
||||
setupCache,
|
||||
useCache
|
||||
} from './cache/create';
|
||||
export { buildStorage } from './storage/build';
|
||||
export { buildMemoryStorage } from './storage/memory';
|
||||
export { buildWebStorage } from './storage/web-api';
|
||||
export * from './index';
|
||||
|
||||
console.warn(
|
||||
'You are using a development build. Make sure to use the correct build in production\nhttps://axios-cache-interceptor.js.org/pages/installing'
|
||||
'You are using a development build. Make sure to use the correct build in production\nhttps://axios-cache-interceptor.js.org/#/pages/installing'
|
||||
);
|
||||
|
||||
@ -1,11 +1,18 @@
|
||||
export * from './cache/axios';
|
||||
export * from './cache/cache';
|
||||
export * from './cache/create';
|
||||
export * from './header/interpreter';
|
||||
export * from './header/types';
|
||||
export * from './interceptors/request';
|
||||
export * from './interceptors/response';
|
||||
export * from './interceptors/types';
|
||||
export * as InterceptorUtil from './interceptors/util';
|
||||
export * from './storage/build';
|
||||
export * from './storage/memory';
|
||||
export * from './storage/types';
|
||||
export * from './storage/web-api';
|
||||
export * from './util/cache-predicate';
|
||||
export * from './util/headers';
|
||||
export * from './util/key-generator';
|
||||
export * from './util/types';
|
||||
export * from './util/update-cache';
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import type { CacheAxiosResponse, CacheProperties } from '..';
|
||||
import type { CacheAxiosResponse } from '../cache/axios';
|
||||
import type { CacheProperties } from '../cache/cache';
|
||||
import type { CachePredicateObject } from './types';
|
||||
|
||||
/** Returns true if the response should be cached */
|
||||
|
||||
@ -31,7 +31,7 @@ export type KeyGenerator = <R = any, D = any>(
|
||||
options: CacheRequestConfig<R, D>
|
||||
) => string;
|
||||
|
||||
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>;
|
||||
export type MaybePromise<T> = T | Promise<T> | PromiseLike<T>;
|
||||
|
||||
export type CacheUpdater<R, D> =
|
||||
| 'delete'
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { AxiosStorage } from '..';
|
||||
import type { CacheAxiosResponse } from '../cache/axios';
|
||||
import type { AxiosStorage } from '../storage/types';
|
||||
import type { CacheUpdater } from './types';
|
||||
|
||||
/** Function to update all caches, from CacheProperties.update, with the new data. */
|
||||
|
||||
@ -3,15 +3,6 @@ import { buildMemoryStorage } from '../src/storage/memory';
|
||||
import { buildWebStorage } from '../src/storage/web-api';
|
||||
|
||||
describe('test bundle imports', () => {
|
||||
it('tests browser ', async () => {
|
||||
const bundle = await import('../src/index.browser');
|
||||
|
||||
expect(bundle.setupCache).toBe(setupCache);
|
||||
expect(bundle.isAxiosCacheInterceptor).toBe(isAxiosCacheInterceptor);
|
||||
expect(bundle.buildMemoryStorage).toBe(buildMemoryStorage);
|
||||
expect(bundle.buildWebStorage).toBe(buildWebStorage);
|
||||
});
|
||||
|
||||
it('test development bundle imports', async () => {
|
||||
const oldWarn = console.warn;
|
||||
console.warn = jest.fn();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import Axios from 'axios';
|
||||
import { AxiosCacheInstance, CacheProperties, setupCache } from '../../src';
|
||||
import type { CacheInstance } from '../../src/cache/cache';
|
||||
import type { AxiosCacheInstance } from '../../src/cache/axios';
|
||||
import type { CacheInstance, CacheProperties } from '../../src/cache/cache';
|
||||
import { setupCache } from '../../src/cache/create';
|
||||
import { Header } from '../../src/util/headers';
|
||||
|
||||
export const XMockRandom = 'x-mock-random';
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { Axios } from 'axios';
|
||||
import { buildMemoryStorage, isStorage } from '../../src';
|
||||
import { isStorage } from '../../src/storage/build';
|
||||
import { buildMemoryStorage } from '../../src/storage/memory';
|
||||
import { mockAxios } from '../mocks/axios';
|
||||
|
||||
it('tests isStorage function', () => {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { CachedStorageValue } from '../../src';
|
||||
import type { CachedStorageValue } from '../../src/storage/types';
|
||||
import { isCachePredicateValid } from '../../src/util/cache-predicate';
|
||||
import { mockAxios } from '../mocks/axios';
|
||||
import { createResponse } from '../utils';
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { CachedStorageValue } from '../../src';
|
||||
import type { CachedStorageValue } from '../../src/storage/types';
|
||||
import { defaultKeyGenerator } from '../../src/util/key-generator';
|
||||
import { mockAxios } from '../mocks/axios';
|
||||
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"target": "ES6",
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"module": "ESNext"
|
||||
},
|
||||
"include": ["src/index.*.ts"]
|
||||
}
|
||||
@ -2,8 +2,10 @@
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"target": "ES6"
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"declaration": false,
|
||||
"declarationMap": false
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["src/index.*.ts"]
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
@ -10,10 +10,12 @@ const TerserWebpackPlugin = require('terser-webpack-plugin');
|
||||
* entry: string;
|
||||
* esTarget: string;
|
||||
* minimize: boolean;
|
||||
* override?: import('typescript').CompilerOptions;
|
||||
* library?: import('webpack').LibraryOptions;
|
||||
* }} options
|
||||
* @returns {import('webpack').Configuration}
|
||||
*/
|
||||
const config = ({ output, esTarget, minimize, entry }) => ({
|
||||
const config = ({ output, esTarget, minimize, entry, override = {}, library }) => ({
|
||||
mode: 'production',
|
||||
|
||||
entry: path.resolve(__dirname, 'src', entry),
|
||||
@ -24,7 +26,8 @@ const config = ({ output, esTarget, minimize, entry }) => ({
|
||||
filename: output,
|
||||
library: {
|
||||
type: 'umd',
|
||||
name: 'AxiosCacheInterceptor'
|
||||
name: 'AxiosCacheInterceptor',
|
||||
...library
|
||||
},
|
||||
chunkFormat: 'module'
|
||||
},
|
||||
@ -44,9 +47,10 @@ const config = ({ output, esTarget, minimize, entry }) => ({
|
||||
test: /\.(ts|js)$/,
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
configFile: path.resolve(__dirname, 'tsconfig.browser.json'),
|
||||
configFile: path.resolve(__dirname, 'tsconfig.build.json'),
|
||||
compilerOptions: {
|
||||
target: esTarget
|
||||
target: esTarget,
|
||||
...override
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,21 +71,35 @@ module.exports = [
|
||||
minimize: false
|
||||
}),
|
||||
config({
|
||||
esTarget: 'es2015',
|
||||
entry: 'index.browser.ts',
|
||||
esTarget: 'es2015', // ES6
|
||||
entry: 'index.ts',
|
||||
output: 'index.min.js',
|
||||
minimize: true
|
||||
}),
|
||||
config({
|
||||
esTarget: 'es5',
|
||||
entry: 'index.browser.ts',
|
||||
entry: 'index.ts',
|
||||
output: 'index.es5.min.js',
|
||||
minimize: true
|
||||
}),
|
||||
config({
|
||||
esTarget: 'es2020',
|
||||
entry: 'index.browser.ts',
|
||||
entry: 'index.ts',
|
||||
output: 'index.es2020.min.js',
|
||||
minimize: true
|
||||
}),
|
||||
config({
|
||||
esTarget: 'es2017',
|
||||
entry: 'index.ts',
|
||||
output: 'index.js',
|
||||
minimize: true,
|
||||
library: {
|
||||
type: 'commonjs',
|
||||
name: undefined
|
||||
},
|
||||
override: {
|
||||
declaration: true,
|
||||
declarationMap: true
|
||||
}
|
||||
})
|
||||
];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user