mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
3.0 KiB
3.0 KiB
English | 简体中文
vuepress-plugin-netlify-functions
If your vuepress site is deployed on netlify and you want to be able to use netlify functions for serverless.
You may need this plugin to provide support.
Features
- On the Vuepress local server, start a
Netlify Functionslocal service to help you debugfunctionslocally. - Generate a usable
netlify.tomland add the appropriate 'functions' configurations if you have already creatednetlify.toml - This plugin does not provide specific
functionscripts, onlynetlify functionssupport; It can be used directly in themes, directly in vuepress projects, or based on this plugin, new plugins can be developed to provide more detailed functionality support. - Use
dotenvto provide support similar toNetlify Environment variablesin the local service environment. Create.envfiles in the project root directory to hold development-time environment variables
Install
npm install vuepress-plugin-netlify-functions
# or
pnpm add vuepress-plugin-netlify-functions
# or
yarn add vuepress-plugin-netlify-functions
Usage
-
In a Vuepress project, or in a Vuepress theme
// .vuepress/config.[jt]s import { netlifyFunctionsPlugin } from 'vuepress-plugin-netlify-functions' export default { // ... plugins: [ netlifyFunctionsPlugin() ] // ... } -
In a vuepress plugin:
import { useNetlifyFunctionsPlugin } from 'vuepress-plugin-netlify-functions' function myPlugin(): Plugin { return (app: App) => { const { // proxy prefix, default: /api proxyPrefix, preparePluginFunctions, generatePluginFunctions } = useNetlifyFunctionsPlugin(app, { // Specifies the functions directory for the plugin where the relevant scripts are developed directory: path.resolve(__dirname, 'functions') }) return { name: 'vuepress-plugin-myPlugin', onPrepared: () => preparePluginFunctions(), onGenerated: () => generatePluginFunctions(), } } }
Methods
netlifyFunctionsPlugin(options)
plugin function
In the Vuepress configuration, or in the Vuepress topic configuration.
options
-
options.sourceDirectoryfunctions source directory。@default `app.dir.source('.vuepress/functions')。
-
options.destDirectoryfunctions output directory@default `app.dir.dest('function')
-
options.proxyPrefixserver proxy prefix@default
/api。functions request to proxy
^/api/*
useNetlifyFunctionsPlugin(app, options)
Used in the plugin when developing the VuePress plugin
app: App
options
-
options.directoryFunctions development directory in plugin
Example
- vuepress-plugin-page-collection Log and display the number of page views/visits of blog articles by connecting
leanCloudin functions based onnetlify-functions