Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

it does not work in vue cli preset #342

Open
wubolin opened this issue May 31, 2020 · 0 comments
Open

it does not work in vue cli preset #342

wubolin opened this issue May 31, 2020 · 0 comments

Comments

@wubolin
Copy link

wubolin commented May 31, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant