1. serverless-hooks-vue-loader

serverless-hooks-vue-loader

serverless-hooks-vue-loader

将代码中对于后端 Api 函数引用转为前端 Vue 框架的 ajax 请求

// web前端本地调试代码, 获取接口数据直接函数导入
import { hello } from '../api/lambda/index'

// start or build ,webpack配置 serverless-hooks-loader, 构建build编译

const hello = (params) =>  request('/index/hello', params);

当前兼容 webpack3

Vue 项目使用

npm install serverless-hooks-vue-loader --save-dev

在webpack的module内配置loader

# webpack 调用loader是栈的调用方式, FILI模式, 所有该插件需要push到rules。
webpack的module.rules.push({
    {
        test: /\.js$/,
        loader: "serverless-hooks-vue-loader",
        include: [path.resolve(__dirname, "../src/apis/lambda")],
        exclude: ["node_modules"]
      }
})