Skip to content

一体化如何创建入口文件, 而不是通过 hooks 启动项目 #3470

Closed Answered by czy88840616
achen-11 asked this question in Q&A
Discussion options

You must be logged in to vote

经过测试,可行的方案如下:

为了不污染源码目录,以下方式最好在构建服务上执行

  • 1、执行 npm run build,产生 dist 目录
  • 2、拷贝 dist/midway.config.js 到根目录
  • 3、重命名或者删除根目录的 midway.config.ts 文件
  • 4、在根目录创建 bootstrap.js 文件,内容如下
  • 5、在根目录执行 NODE_ENV=production bootstrap.js 启动即可

bootstrap.js 文件内容如下。

const { Bootstrap } = require('@midwayjs/bootstrap');
const { join } = require('path');
Bootstrap
  .configure({
    appDir: __dirname,
    baseDir: join(__dirname, 'dist'),
    ignore: [
      '**/_client/**',
    ],
    globalConfig: {
      koa: {
        port: 7001,
      }
    }
  })
  .run();

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by czy88840616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
status: closed / duplicate This issue or pull request already closed or exists type: question / discussion This issue or pull request need be discussion
2 participants