npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pm2-deploy-xxjss

v1.0.0

Published

centos7 + PM2 + Webpack 云部署

Downloads

5

Readme

webpack 的 dist 包 自动化部署 插件

本插件 是-只用 服务部署插件,
基于 centOS 7 + pm2  用于部署 webpack 生成的dist 包,
自动化部署到远程服务器,并实现自动重启 服务

该插件 主要有三个 功能

    1.  初始化服务器 可以自动联网 安装 node 环境;
        上传服务 配置文件;

    2. 远程服务器,自动创建 环境依赖文件-所需存放文件夹、自动创建 项目所需文件夹;
    
    3.  build 项目 为dist 文件 并压缩 为 dist.zip 文件 并上传到 远程服务器 指定目录下  /data/www/dist.zip ;
        远程服务器 解压 dist.zip 文件 到 /data/www/dist 目录下;
        重启 nginx 服务;
        删除 远程服务器 指定目录下的30天以前的(自定义源码可改过期时间,默认30天) dist.zip 文件; 
        删除 本地 dist.zip 文件; 
    

安装

npm i pm2-deploy-xxjss

使用

插件初始化 会在 项目根路径 生成一个配置文件;
    /ssDeploy/deployConfig.js -> 服务器基本信息 和文件存放路径
    /ssDeploy/server.js -> pm2 运行 配置文件 默认只有 '/api'
    /ssDeploy/prod.config.js -> pm2 运行 配置文件 配置服务器 运行后台信息

命令解析

    带有 ‘init’  的命令 表示 该项目初始化命令,主要用于,创建 nginx 运行环境 和项目 存放路径;
    已有 pm2 运行环境 和项目 存放路径 的项目 无需 执行 init 命令;

配置 远程服务器

// =============================================== deploy.js==============================
// 配置远程服务器目录
let remoteDirectory = '/data/competition/web';
// 服务地址配置
let serverConfig;
switch (args[0]) {
    case 'production':
        serverConfig = {
            host: '**.***.***.***',
            port: 22,
            username: 'root',
            password: '**************',
        };
        break;
    case 'test':
        serverConfig = {
            host: '**.***.***.***',
            port: 22,
            username: 'root',
            password: '**************',
        };
        break;
    case 'development':
        serverConfig = {
            host: '**.***.***.***',
            port: 22,
            username: 'root',
            password: '**************',
        };
        break;
    default:
        console.error('连接异常:请重新执行dev:deploy、test:deploy、production:deploy');
        process.exit(1);
}
// =============================================== server.js ==============================
    const path = require('path');
    const compression = require('compression');
    const express = require('express');
    const app = express();
    const { createProxyMiddleware } = require('http-proxy-middleware');
    const ejs = require('ejs');
    const indexRouter = require('./indexRouter');
    const config = require('./prod.config');
    app.use(compression());
    // 模板配置
    // eslint-disable-next-line no-underscore-dangle
    app.engine('html', ejs.__express);
    app.set('view engine', 'html');
    app.set('views', path.join(__dirname, '../dist')); // 项目文件 位置
    
    // 静态资源配置
    app.use('/', express.static(path.join(__dirname, '../dist')));
    
    // api代理配置
    app.use('/api', createProxyMiddleware(config.proxy['/api']));

    <!-- 
        多个 代理 依次累加 就行  只需修改 '/api' -> '/pro' 
        // pro代理配置
        app.use('/pro', createProxyMiddleware(config.proxy['/pro']));
    -->
    // 路由配置
    app.use('/', indexRouter);
    // 监听端口
    app.listen(config.port);
  
// =============================================== prod.config.js ==============================

    module.exports = {
      // proxy: 'http://***.***.***.***:8888',
      proxy: {
        '/api': {
          target: 'http://***.***.***.***:8888',
          changeOrigin: true,
          pathRewrite: { '^/api': '' },
        },
      },
      port: 8080,
    };