【问题标题】:Heroku review app looks for app.development.json instead of productionHeroku 审查应用程序寻找 app.development.json 而不是生产
【发布时间】:2019-08-07 20:02:33
【问题描述】:

我有一个多包 Angular 项目,其中主要项目需要其他两个项目才能成功构建。我们在 GitLab 上托管我们的项目,并通过其 CI 运行器,我们希望创建在生产模式下运行的动态审查应用程序,以查看合并请求中所做的任何视觉更改。问题是,即使我已经指定它应该在生产模式下运行,它在开发中运行并要求 app.development.json 不存在。

在 angular.json 中,我指定每当构建一个包时,输出文件夹将是/dist/<package-name>/

我创建了一个 server.js 文件,它获取所有静态文件并为它们提供服务。

const path = require('path');

const express = require('express');
const app = express();
// Run the app by serving the static files
// in the dist directory
app.use('/assets/config/app.production.json', express.static(path.join(process.cwd(), 'dist/registrar/assets/config/app.production.json'), {
  lastModified: false,
  cacheControl: false,
  etag: false
}));
app.use(express.static(path.join(process.cwd(), '/dist/registrar/')));
// Start the app by listening on the default
// Heroku port
app.listen(process.env.PORT || 8080);

// For all GET requests, send back index.html
// so that PathLocationStrategy can be used
app.get('/*', function(req, res) {
  res.sendFile(path.join(process.cwd() + '/dist/registrar/index.html'));
});

我添加了heroku-postbuild 执行以下操作的脚本

"heroku-postbuild": "npm i && cd packages/theme && npm i && cd ../common && npm i && cd ../.. && npm run ng -- build -- common && npm run ng -- build -- registrar --aot --prod --source-map=true" 

让我们分解一下为什么我需要这个脚本。我有一个名为 registrar 的主包,它需要主题包和通用包才能运行。我在每个包中都有一个依赖项,这就是我运行npm i 三次的原因。 我还将源映射设置为真实,以便在审查阶段具有调试功能。

gitlab ci 通过(因为应用程序创建成功)但是当我被重定向到审查应用程序时,我收到一个错误,即 app.development.json 丢失。

每当我将 app.production.json 重命名为 app.development.json 时,应用程序都会成功运行,但处于开发模式。

【问题讨论】:

    标签: angular heroku gitlab-ci npm-scripts


    【解决方案1】:

    在我们的例子中,我们必须禁用优化并将 heroku-postbuild 脚本更改为 ... npm run ng -- build registrar --optimization=false --aot --prod --source-map=true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-19
      • 2022-07-26
      相关资源
      最近更新 更多