0.0.5 • Published 3 years ago

@serverless-devs/nodejs-deploy-best-practice v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

nodejs-deploy-best-practice

Serverless-Devs Nodejs组件开发最佳实践工具包,主要实现下面几个能力

  • 只安装部署dependencies的package,减少部署包体积。 npm install --prodution
  • rollup, esbuild,webpack 减少包体积,进而减少冷启动时间
  • 统一部署流程,Nodejs生态的部署组件交互行为保持一致

使用方法

const BestPractice = require("@serverless-devs/nodejs-deploy-best-practice");
class NuxtComponent extends BestPractice {
  constructor() {
    super();
  }
  async deploy(inputs) {
    return await super.deploy(
      inputs,
      (deployPath) => [
        {
          title: "Copy files to publish path",
          task: async () => {
            await fs.copy(
              path.join(__dirname, "template"),
              path.join(deployPath),
              {}
            );
            await fs.copy(
              path.join(currentPath, "static"),
              path.join(deployPath, "static")
            );
            await fs.copy(
              path.join(currentPath, "./nuxt.config.js"),
              path.join(deployPath, "./nuxt.config.js")
            );
          },
        },
      ],
      (deployPath) => [
        {
          title: "Run Nuxt build",
          task: async () => {
            await execa("npm", ["run", "build"]);
            await fs.move(
              path.join(currentPath, ".nuxt"),
              path.join(deployPath, ".nuxt"),
              { overwrite: true }
            );
          },
        },
      ]
    );
  }
}