gpt4 book ai didi

node.js - 有什么办法可以从 Nuxt+Node 项目中生成可执行文件 (.exe) 吗?

转载 作者:行者123 更新时间:2023-12-05 06:51:50 24 4
gpt4 key购买 nike

我有一个 NuxtJS 项目,它需要一个 NodeJS 程序在后面运行以实现某些功能和逻辑。项目结构如下:

api
assets
components
layouts
middleware
pages
plugins
server
static
store
nuxt.config.js
package.json

nuxt.config.js

module.exports =  {
head: {
titleTemplate: '%s',
title: 'Project',
htmlAttrs: {
lang: 'en'
},
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' }
]
},

css: [
'@/assets/css/main.scss'
],

plugins: [
],

components: true,

buildModules: [
'@nuxtjs/vuetify'
],

modules: [
'nuxt-socket-io',
'nuxt-i18n',
'@nuxtjs/axios',
'@nuxtjs/auth-next'
],

io: {
sockets: [
{
name: 'main',
url: process.env.APP_SERVER_URL,
default: true
}
]
},

i18n: {
locales: [
{
code: 'en',
file: 'en-US.js'
}
],
lazy: true,
langDir: 'lang/',
defaultLocale: 'en'
},

serverMiddleware: [
{ path: '/api', handler: '~/api/index.js' },
],

axios: {
baseURL: process.env.APP_SERVER_URL,
},

vuetify: {
customVariables: ['~/assets/variables.scss'],
theme: {
dark: true,
themes: {
dark: {},
light: {}
}
}
},

build: {
extend(config) {}
}
}

package.json

{
"name": "my-project",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nodemon -w server -w nuxt.config.js server",
"build": "nuxt generate",
"start": "cross-env NODE_ENV=production node server",
"generate": "nuxt generate"
},
"dependencies": {
"@nuxtjs/auth-next": "5.0.0-1611574754.9020f2a",
"@nuxtjs/axios": "^5.12.5",
"body-parser": "^1.19.0",
"core-js": "^3.8.3",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"http": "0.0.1-security",
"moment": "^2.29.1",
"nuxt": "^2.14.12",
"nuxt-i18n": "^6.18.0",
"nuxt-socket-io": "^1.1.14"
},
"devDependencies": {
"@nuxtjs/vuetify": "^1.11.3",
"cross-env": "^7.0.3",
"nodemon": "^2.0.7"
}
}

server/index.js

require('dotenv').config();

const isProd = process.env.NODE_ENV === 'production'
const http = require('http')
const app = require('express')()
const server = http.createServer(app)
const io = require('socket.io')(server)
const axios = require('axios')

const { Nuxt, Builder } = require('nuxt')
const config = require('../nuxt.config.js');
config.dev = !isProd;

const nuxt = new Nuxt(config)
const { host, port } = nuxt.options.server
if (config.dev) {
const builder = new Builder(nuxt)
builder.build()
} else {
nuxt.ready()
}
app.use(nuxt.render)

server.listen(port, () => {
console.log(`Server listening on http://${host}:${port}`)
});

// other logic

我需要一个可以安装在其他计算机上的 exe 来运行 Nodejs 服务器和 Nuxt 东西,就像我通过 npm run devnpm run build/start< 运行代码一样 在本地的开发计算机中。

我已经通过运行 nexe -i server 尝试了 nexe 但没有成功。我还有其他方法吗?

谢谢。

最佳答案

我想你可以看看pm2 .你可以用它运行 Node 服务器和其他东西。

关于node.js - 有什么办法可以从 Nuxt+Node 项目中生成可执行文件 (.exe) 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66066951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com