我想启用github页面以便在nuxt中进行部署。在docs之后,尽管我在conf文件中无法正确找到它。
这是他们注意添加到文件中的内容。我已将其添加到文件中的多个位置,但每次都出错。
/* nuxt.config.js */
// only add `router.base = '/<repository-name>/'` if `DEPLOY_ENV` is `GH_PAGES`
const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {
router: {
base: '/<repository-name>/'
}
} : {}
export default {
...routerBase
}
我的出口代码。
module.exports = {
mode: 'spa',
const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ?
{router: {base: '/mortalcatalyst.github.io/'}} :
{} export default {router: {base: '/mortalcatalyst.github.io/'}},
/*
** Headers of the page
*/
head: {
title: pkg.name,
meta: [
{charset: 'utf-8'},
{name: 'viewport', content: 'width=device-width, initial-scale=1'},
{hid: 'description', name: 'description', content: pkg.description}
],
link: [{rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'}]
}, # rest of config (standard)
错误
FATAL Invalid or unexpected token 22:06:37
const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {
^
SyntaxError: Invalid or unexpected token
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
╭──────────────────────────────────────────────╮
│ │
│ ✖ Nuxt Fatal Error │
│ │
│ SyntaxError: Invalid or unexpected token │
│ │
╰──────────────────────────────────────────────╯
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! github@1.0.0 generate: `nuxt generate`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the github@1.0.0 generate script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
答案 0 :(得分:2)
您在第三行有一个格式错误的JS对象:
module.exports = {
mode: 'spa',
const routerBase = ... // it must be a "key: value" not a "const" declaration
因此,您可以替换为外部声明,然后在...
上使用扩展运算符export default
添加变量:
const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ?
{router: {base: '/mortalcatalyst.github.io/'}} :
{}
export default {
...routerBase,
/*
** Headers of the page
*/
head: {
}
}