Skip to content

Commit 7f5f33b

Browse files
committed
fix: axios not installed
1 parent cdef7f7 commit 7f5f33b

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ This is the fork of [vue-cli-plugin-axios](https://www.npmjs.com/package/vue-cli
1010

1111
For legacy Vue2 CLI.
1212

13-
```shell
14-
vue add axios-x
13+
```sh
14+
vue add axios-x
1515
```
1616

1717
## License

Diff for: generator/index.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,33 @@ const {
44
updateMain,
55
} = require("./updater");
66

7+
const {
8+
get,
9+
} = require("axios");
10+
711
module.exports = (api, options) => {
8-
api.extendPackage({
9-
devDependencies: {
10-
axios: "latest",
11-
},
12-
});
12+
// Install latest Axios
13+
get("https://registry.npmjs.org/axios").
14+
then(({ data }) => {
15+
const {
16+
latest: pkgVersion,
17+
} = data["dist-tags"];
18+
api.extendPackage({
19+
devDependencies: {
20+
axios: `${pkgVersion}`,
21+
},
22+
});
23+
});
1324

25+
// Inject config files
1426
api.render({
1527
"./src/plugins/axios.js": "./templates/plugins/axios.js",
1628
}, options);
1729

1830

19-
// adapted from https://github.com/Akryum/vue-cli-plugin-apollo/blob/master/generator/index.js#L68-L91
31+
// Adapted from https://github.com/Akryum/vue-cli-plugin-apollo/blob/master/generator/index.js#L68-L91
2032
api.onCreateComplete(() => {
21-
// Modify main.js
33+
// Inject "import axios" into main.js/main.ts
2234
updateMain(api, (src) => {
2335
const vueImportIndex = src.findIndex(
2436
(line) => line.match(/^import Vue/),

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"plugin"
1717
],
1818
"devDependencies": {
19-
"axios": "latest",
19+
"axios": "^1.7.7",
2020
"vue": "^2.7.16"
2121
}
2222
}

0 commit comments

Comments
 (0)