将VueJS部署到GitHub Pages

时间:2018-11-28 15:13:00

标签: vue.js github-pages

我已经按照guide的步骤逐步将VueJS应用程序部署到GitHub页面,并引发了错误gh-pages

我的仓库(#!/usr/bin/env sh # abort on errors set -e # build npm run build # navigate into the build output directory cd dist # if you are deploying to a custom domain # echo 'www.example.com' > CNAME git init git add -A git commit -m 'deploy' # if you are deploying to https://<USERNAME>.github.io # git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master # if you are deploying to https://<USERNAME>.github.io/<REPO> git push -f git@github.com:jedrekdomanski/bikeramp-front.git master:gh-pages cd - 分支):https://github.com/jedrekdomanski/bikeramp-front/tree/gh-pages

网站:https://jedrekdomanski.github.io/bikeramp-front/

脚本

https://cli.vuejs.org/guide/deployment.html#github-pages

module.exports = {
  baseUrl: process.env.NODE_ENV === 'production'
    ? '/bikeramp-front/'
    : '/'
}

vue.config.js

gh-pages

我从Your GitHub Pages site is currently being built from the gh-pages branch.开始提供应用程序,就像他们说的那样。

来源

{ ... "private": true, "scripts": { "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot", "build": "cross-env NODE_ENV=production webpack --progress --hide-modules" }, "dependencies": { "axios": "^0.18.0", "chart.js": "^2.7.3", "vue": "^2.4.4", "vue-chartjs": "^3.4.0", "vue-router": "^3.0.1", "vuex": "^3.0.0" }, "devDependencies": { "babel-core": "^6.26.0", "babel-loader": "^7.1.2", "babel-preset-env": "^1.6.0", "babel-preset-stage-2": "^6.24.1", "cross-env": "^5.0.5", "css-loader": "^0.28.11", "file-loader": "^1.1.4", "vue-loader": "^13.0.5", "vue-template-compiler": "^2.4.4", "webpack": "^3.6.0", "webpack-dev-server": "^2.9.1" } } 我在做什么错了?

package.json

 #define LogFunction(str)       fprintf(stdout, "%s: %s\n",__FUNCTION__,(str))
 #define LogPrintf(f_, ...)     fprintf(stdout, (f_), ##__VA_ARGS__)

2 个答案:

答案 0 :(得分:0)

由于相对路径有局限性,因此可能尝试将library(shiny) library(RSQLite) library(data.table) library(DT) library(dplyr) library(rclipboard) library(shinyBS) ui <- function(request) { fluidPage(rclipboardSetup(), DT::dataTableOutput("x1"), column( 12, column(3,tags$div(title="forecast", numericInput("budget_input", label = ("Total Forecast"), value = 2))), column(2, textInput(inputId = "description", label = "Bookmark description", placeholder = "Data Summary")), column(2, bookmarkButton(id="bookmarkBtn"))), column(2, actionButton("opt_run", "Run")), DT::dataTableOutput("urlTable", width = "100%"), tags$style(type='text/css', "#bookmarkBtn { width:100%; margin-top: 25px;}") ) } server <- function(input, output, session) { con <- dbConnect(RSQLite::SQLite(), "bookmarks.db", overwrite = FALSE) myBookmarks <- reactiveValues(urlDF = NULL) observeEvent(input$bookmarkBtn, { session$doBookmark() }) observeEvent(input$opt_run, { cat('HJE') }) output$x1 <- DT::renderDataTable({ input$opt_run isolate({ datatable( df %>% mutate(Current = as.numeric(Current)*(input$budget_input)), selection = 'none', editable = TRUE ) }) }) if(dbExistsTable(con, "Bookmarks")){ tmpUrlDF <- data.table(dbReadTable(con, "Bookmarks")) myBookmarks$urlDF <- tmpUrlDF[, Timestamp := as.POSIXct(Timestamp, origin="1970-01-01 00:00")] } else { myBookmarks$urlDF <- NULL } session$onSessionEnded(function() { tmpUrlDF <- isolate({myBookmarks$urlDF}) if(!is.null(tmpUrlDF)){ dbWriteTable(con, "Bookmarks", tmpUrlDF, overwrite = TRUE) } dbDisconnect(con) }) setBookmarkExclude(c("bookmarkBtn", "description", "urlTable_cell_clicked", "urlTable_rows_all", "urlTable_rows_current", "urlTable_rows_selected", "urlTable_search", "urlTable_state", "urlTable_row_last_clicked")) df <- data.table(Channel = c("A", "B","C"), Current = c("2000", "3000","4000"), Modified = c("2500", "3500","3000"), New_Membership = c("450", "650","700")) shinyInput <- function(FUN, len, id, ...) { inputs <- character(len) for (i in seq_len(len)) { inputs[i] <- as.character(FUN(paste0(id, i), ...)) } inputs } onBookmarked(fun=function(url){ if(!url %in% myBookmarks$urlDF$URL){ if(is.null(myBookmarks$urlDF)){ myBookmarks$urlDF <- unique( data.table( Description = input$description, URL = paste0("<a href='", url, "'>", url, "</a>"), Share = shinyInput(actionButton, 10, 'button_', label = "Assessment", onclick = 'Shiny.onInputChange(\"select_button\", this.id)' ), Timestamp = Sys.time(), Session = session$token, User = Sys.getenv("USERNAME") ), by = "URL" ) } else { myBookmarks$urlDF <- unique(rbindlist(list( myBookmarks$urlDF, data.table( Description = input$description, URL = paste0("<a href='", url, "'>", url, "</a>"), Share = shinyInput(actionButton, 10, 'button_', label = "Assessment", onclick = 'Shiny.onInputChange(\"select_button\", this.id)' ), Timestamp = Sys.time(), Session = session$token, User = Sys.getenv("USERNAME") ) )), by = "URL") } } }) observeEvent(input$select_button, { showModal(urlModal( myBookmarks$urlDF[input$urlTable_rows_selected,URL], title = "You have selected a row!" )) }) output$urlTable = DT::renderDataTable({ req(myBookmarks$urlDF) myBookmarks$urlDF[User %in% Sys.getenv("USERNAME")] }, escape=FALSE) } enableBookmarking(store = "url") shinyApp(ui, server) 设置为完整路径而不是相对路径

引用:https://cli.vuejs.org/config/#publicpath

更新

有趣的是,切换到完整路径后我注意到它可以工作,然后切换回相对路径时,它似乎仍然可以工作。

答案 1 :(得分:0)

以下是我将我的 Vuejs 应用程序部署到 github 页面的方法:

我在根项目中添加了一个新文件(在 package.json 旁边,...):vue.config.js

我在里面写:

module.exports = {
  publicPath: "/something/",
  outputDir: "docs",
};

这样您的网址将是:

name.github.io/something/

“docs”给出了 npm run build 的输出文件夹,因为 Github 允许您在 GitHub 页面的 /(root) 和 /docs 之间进行选择。因此,在这种情况下,在项目设置中的 GitHub 上,转到页面并为源选择 /docs。

之后你只需编写以下git命令:

yourProject(main)$ npm run build
git add .
git status      (to be sure)
git commit -am "your commentar"
git branch -M main      (only if yourProject(master)is written instead of sfes(main) => GitHub changed master to main)
git push -u origin main