我有一个NuxtJS项目,它需要一个运行在后面的NodeJS程序来执行一些功能和逻辑。项目结构如下:
api
assets
components
layouts
middleware
pages
plugins
server
static
store
nuxt.config.js
package.jsonnuxt.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 dev或npm run build/start的代码一样。
我已经通过运行nexe -i server尝试过nexe,但没有成功。我还有别的办法吗?
谢谢。
发布于 2021-02-05 17:28:46
我想你可以看看pm2。您可以使用它运行节点服务器和其他东西。
发布于 2022-05-11 17:07:45
将Node.js应用程序编译成.exe文件
用于将JavaScript文件编译为可执行文件的两个最常用的包是:
nexe:它是一个简单的命令行实用程序,它将您的Node.js应用程序编译成一个可执行文件。默认情况下,它将其转换为Windows可执行文件。
pkg:这是一个Node.js包,它可以将您的Node.js应用程序转换成多个可执行文件,用于各种操作系统(全部都是一次)或单个操作系统。
https://stackoverflow.com/questions/66066951
复制相似问题