侧边栏壁纸
博主头像
xuesheng博主等级

分享web知识,学习就是取悦自己!

  • 累计撰写 118 篇文章
  • 累计创建 14 个标签
  • 累计收到 3 条评论

目 录CONTENT

文章目录

Nuxt+PM2部署,使用ecosystem.config启动与开发经验

xuesheng
2019-06-11 / 0 评论 / 0 点赞 / 355 阅读 / 2,928 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-01-04,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

记录config配置

GIT地址;https://gitee.com/lingtin/common_template_admin

ecosystem.config


module.exports = {
    "apps": [{
        "name": "mp",
        "script": "server/index.js",
        "log_date_format": "YYYY-MM-DD HH:mm:ss",
        "error_file": "log/node-app/node-app.error.log",
        "out_file": "log/node-app.out.log",
        "instances": 3,
        "min_uptime": "1000s",
        "max_restarts": 30,
        "max_memory_restart": "1G",
        "merge_logs": false,
        "exec_mode": "cluster_mode",
        "autorestart": true,
        "vizion": false,
        "exec_interpreter": "node",
        "env": {
            "NODE_ENV": "production" // 环境变量,object类型,如{"NODE_ENV":"production", "ID": "42"};
        },
        "env_production": {
            "NODE_ENV": "production",
        }
    }]
}

nuxt.config


const PUR = process.env.npm_package_config_nuxt_base_url;

const base_url = process.env.NODE_ENV != 'development' ? PUR : 'http://192.168.0.125:8074/'

console.log('base_url:' + base_url)

const proxy_url = process.env.NODE_ENV != 'development' ? base_url : "/api";

const webmp = process.env.npm_package_config_nuxt_webmp;

console.log('spa:' + process.env.NODE_MODE)
console.log('NODE_ENV:' + process.env.NODE_ENV)

module.exports = {
    mode: process.env.NODE_MODE ? 'spa' : '',

    /*
    
     ** Headers of the page
     */

    head: {
        title: "",
        meta: [{
                charset: 'utf-8'
            },
            {
                name: 'viewport',
                content: 'width=device-width, initial-scale=1'
            },
            {
                hid: 'description',
                name: 'description',
                content: ""
            }
        ],
        link: [{
            rel: 'icon',
            type: 'image/x-icon',
            href: '/favicon.ico'
        }]
    },

    /*
     ** Customize the progress-bar color
     */
    loading: {
        color: '#3399ff'
    },
    pageTransition: "bounce",
    /*
     ** Global CSS
     */
    css: [
        'iview/dist/styles/iview.css',
        '@/static/styles/comm.css'
    ],

    /*
     ** Plugins to load before mounting the App
     */
    plugins: [
        '@/plugins/iview',
        '@/plugins/defa',
        '@/plugins/storage',
        '@/plugins/axios',
        '@/plugins/apis/user',
        '@/plugins/apis/sys',
        { src: '@/plugins/validate', mode: 'client' },
        { src: '@/plugins/auth', mode: 'client' }
    ],

    /*
     ** Nuxt.js modules
     */
    env: {
        baseUrl: base_url
    },
    modules: [
        // Doc: https://axios.nuxtjs.org/usage
        '@nuxtjs/axios',
        '@nuxtjs/moment'
    ],
    moment: {
        locales: ['es-us']
    },
    /*
     ** Axios module configuration
     */
    axios: {
        proxy: true, // Can be also an object with default options
        baseURL: proxy_url,
        browserBaseURL: proxy_url,
    },
    proxy: {
        '/api/': {
            target: base_url,
            pathRewrite: {
                '^/api': ''
            }
        },
        '/public': {
            target: base_url,
            pathRewrite: {
                '^/public': '/public/'
            }
        }

    },

    router: {
        // 在每页渲染前运行 middleware/user-agent.js 中间件的逻辑
        middleware: ['user-agent', 'auth'],
        // 所有页面渲染后滚动至顶部
        scrollBehavior: function(to, from, savedPosition) {
            return {
                // x: 0,
                y: 0
            }
        },
        // 扩展自定义路由
        extendRoutes(routes, resolve) {
            routes.push({
                name: '404',
                path: '*',
                component: resolve(__dirname, 'pages/Error/404.vue')
            })
        },
        base: process.env.NODE_MODE ? `/${webmp}/` : ''
    },


    /*
     ** Build configuration
     */
    build: {
        /*
         ** You can extend webpack config here
         */
        extend(config, ctx) {},
        terser: {
            sourceMap: false,
        }
    },
    buildDir: 'nuxt-dist',
    generate: {
        dir: webmp
    },
}

0
博主关闭了所有页面的评论