Akryum / Akryum/vue-cli-plugin-apollo

it does not work in vue cli preset

未关闭
#342 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
477
派生
109
PR 合并指标
30 天内没有已合并 PR

描述

when i put vue-cli-plugin-apollo in my vue-cli preset. the .vuerc file is:

{
"useTaobaoRegistry": false,
"packageManager": "yarn",
"latestVersion": "4.4.1",
"lastChecked": 1590545595795,
"presets": {
"test": {
"useConfigFiles": true,
"plugins": {
"@vue/cli-plugin-babel": {},
"@vue/cli-plugin-typescript": {
"classComponent": true,
"useTsWithBabel": true
},
"@vue/cli-plugin-router": {
"historyMode": true
},
"@vue/cli-plugin-eslint": {
"config": "base",
"lintOn": [
"save"
]
},
"vue-cli-plugin-apollo":{"addServer":false,
"publishSchema":false,
"addExamples":false,
"addApolloEngine":false}
}
}
}

it cannot modify main.js file.

in plugin's generator, the main.js or main.ts don't exist when plugin run.

solution:

replace the code

```
try {
const tsPath = api.resolve('src/main.ts')
const jsPath = api.resolve('src/main.js')

const tsExists = fs.existsSync(tsPath)
const jsExists = fs.existsSync(jsPath)

if (!tsExists && !jsExists) {
throw new Error('No entry found')
}

const file = tsExists ? 'src/main.ts' : 'src/main.js'
api.injectImports(file, `import { createProvider } from './vue-apollo'`)
api.injectRootOptions(file, `apolloProvider: createProvider(),`)
} catch (e) {
api.exitLog(`Your main file couldn't be modified. You will have to edit the code yourself: https://github.com/Akryum/vue-cli-plugin-apollo#manual-code-changes`, 'warn')
}
```

by

```
try {
api.injectImports(api.entryFile, `import { createProvider } from './vue-apollo'`)
api.injectRootOptions(api.entryFile, `apolloProvider: createProvider(),`)
} catch (e) {
api.exitLog(`Your main file couldn't be modified. You will have to edit the code yourself: https://github.com/Akryum/vue-cli-plugin-apollo#manual-code-changes`, 'warn')
}

```
thx.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。