-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
139 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"cSpell.words": [ | ||
"formdata", | ||
"miniprogram", | ||
"treeshake" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
"type": "module", | ||
"version": "1.4.0", | ||
"license": "MIT", | ||
"author": { | ||
"name": "kejunmao", | ||
"email": "[email protected]" | ||
}, | ||
"packageManager": "[email protected]", | ||
"description": "The Axios adapter for uniapp", | ||
"homepage": "https://github.com/uni-helper/axios-adapter", | ||
|
@@ -19,9 +23,34 @@ | |
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.js" | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
} | ||
}, | ||
"./vite": { | ||
"import": { | ||
"types": "./dist/vite.d.ts", | ||
"default": "./dist/vite.js" | ||
}, | ||
"require": { | ||
"types": "./dist/vite.d.cts", | ||
"default": "./dist/vite.cjs" | ||
} | ||
}, | ||
"./webpack": { | ||
"import": { | ||
"types": "./dist/webpack.d.ts", | ||
"default": "./dist/webpack.js" | ||
}, | ||
"require": { | ||
"types": "./dist/webpack.d.cts", | ||
"default": "./dist/webpack.cjs" | ||
} | ||
}, | ||
"./client": { | ||
"types": "./client.d.ts" | ||
|
@@ -57,5 +86,9 @@ | |
}, | ||
"peerDependencies": { | ||
"axios": "^1.5.0" | ||
}, | ||
"dependencies": { | ||
"local-pkg": "^0.4.3", | ||
"unplugin": "^1.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,8 @@ | ||
import { defineConfig } from "vite"; | ||
import uni from "@dcloudio/vite-plugin-uni"; | ||
import uniHelperAxiosAdapter from "@uni-helper/axios-adapter/vite"; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [ | ||
uni(), | ||
{ | ||
name: "vite-plugin-uni-axios", | ||
transform(code, id) { | ||
if (process.env.UNI_PLATFORM?.includes("mp")) { | ||
if (id.includes("/form-data/lib/browser.js")) { | ||
return { | ||
code: code.replace("window", "globalThis"), | ||
}; | ||
} | ||
if (id.includes("/axios/lib/platform/browser/classes/FormData.js")) { | ||
return { | ||
code: `class FormData {};\nexport default FormData;`, | ||
}; | ||
} | ||
if (id.includes("/axios/lib/platform/browser/classes/Blob.js")) { | ||
return { | ||
code: `class Blob {};\nexport default Blob;`, | ||
}; | ||
} | ||
} | ||
}, | ||
}, | ||
], | ||
plugins: [uni(), uniHelperAxiosAdapter()], | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { createUnplugin } from "unplugin"; | ||
import { UserUnpluginOptions } from "./types"; | ||
import { isPackageExists } from "local-pkg"; | ||
|
||
export const unplugin = createUnplugin((options: UserUnpluginOptions = {}) => { | ||
const hasFormDataPolyfill = isPackageExists("miniprogram-formdata"); | ||
const hasBlobPolyfill = isPackageExists("miniprogram-blob"); | ||
return { | ||
name: "unplugin-uni-axios-adapter", | ||
enforce: "pre", | ||
transform(code, id) { | ||
if (process.env.UNI_PLATFORM?.includes("mp")) { | ||
if (id.includes("/form-data/lib/browser.js")) { | ||
return { | ||
code: code.replace("window", "globalThis"), | ||
}; | ||
} | ||
if (id.includes("/axios/lib/platform/browser/classes/FormData.js")) { | ||
return { | ||
code: `${ | ||
hasFormDataPolyfill | ||
? "import FormData from 'miniprogram-formdata';" | ||
: "class FormData {};" | ||
}\nexport default FormData;`, | ||
}; | ||
} | ||
if (id.includes("/axios/lib/platform/browser/classes/Blob.js")) { | ||
return { | ||
code: `${ | ||
hasBlobPolyfill | ||
? "import Blob from 'miniprogram-blob';" | ||
: "class Blob {};" | ||
}\nexport default Blob;`, | ||
}; | ||
} | ||
} | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
import { unplugin } from './unplugin' | ||
|
||
export default unplugin.vite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
import { unplugin } from './unplugin' | ||
|
||
export default unplugin.webpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { defineConfig } from "tsup"; | ||
|
||
export default defineConfig({ | ||
entry: ["src/index.ts"], | ||
entry: ["src/index.ts", "src/vite.ts", "src/webpack.ts"], | ||
format: ["cjs", "esm"], | ||
splitting: true, | ||
sourcemap: true, | ||
clean: true, | ||
treeshake: true, | ||
minify: process.env.NODE_ENV === "production", | ||
minify: true, | ||
external: ["axios"], | ||
dts: true, | ||
}); |