#' @title
#' Use Plumber Backend
#'
#' @description
#' This adds a scaffold and run utilities that allow using plumber as a backend
#' for a static webpack application.
#'
#' @export
dev_use_plumber <- function(envir = parent.frame()) {
# Use Plumber
usethis::use_package("plumber")
# Add the environment plugin
config <- readLines("webpack.common.js")
if (!any(grepl("require('webpack')", config))) {
config <- c("const webpack = require('webpack');", config)
}
plugin <- "var plugins = [\nnew webpack.EnvironmentPlugin(['PLUMBER_BACKEND_API_URL']),"
config[grepl("^var plugins = \\[", config)] <- plugin
writeLines(config, "webpack.common.js")
# Copy the right run utilities
dev_copy_template(
template = "plumber.R",
destination = here::here("R/plumber.R"),
overwrite = TRUE,
envir = envir
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.