繁体   English   中英

如何将角度4添加到现有node.js应用程序

[英]How to add angular 4 to existing node.js application

我有一个node.js应用程序设置为使用typescript。 该应用程序应该部署在heroku上。 node.js应用程序被设置为auth,registration和requests等内容的restful api。

我想知道我需要添加哪些依赖项才能开始在同一个项目中构建一个angular 4应用程序。

我在github上看到了一个问题,建议使用ng init但这不再是一个选项。 ng new创建了一个全新的项目目录,而不是添加依赖项和文件。

在这里还有另一个问题,OP标记他自己的答案是正确的,基本上说“使用流星”。

编辑:我理解如何在本地工作时在node.js应用程序中提供角度2+应用程序,只需构建并提供index.ts文件。 但是我怎样才能让角度开发文件与git中的node.js文件共存,这样我就可以编译它们并将它们一起部署?

我有同样的情况,我在heroku上有一个解析服务器,并希望用Angular对它进行分组。

在我的server.js文件中:

app.use(express.static(__dirname + '/dist'));

(你只需要快递)

我也使用国际化,所以我做了一些快速的事情(早期阶段,请不要判断):

app.get('/', function(req, res) {
  let userLanguage = req.headers["accept-language"];
  let langs = ['fr', 'en'];
  let preferred = userLanguage.substr(0, 2).toLowerCase();
  console.log('User\'s preferred language is ' + preferred.toUpperCase());
  if (langs.indexOf(preferred) >= 0) { res.redirect(preferred); } else { res.redirect('/en'); }
});

我的NG命令:

"postinstall": "npm run build-i18n",
"i18n": "ng xi18n --output-path src/i18n --out-file messages.xlf",
"build-i18n:fr": "ng build --output-path=dist/fr --aot --prod --bh /fr/ --i18n-file=src/i18n/messages.fr.xlf --i18n-format=xlf --locale=fr",
"build-i18n:en": "ng build --output-path=dist/en --aot --prod --bh /en/ --i18n-file=src/i18n/messages.en.xlf --i18n-format=xlf --locale=en",
"build-i18n": "npm run build-i18n:en && npm run build-i18n:fr"

我的应用程序内置于2个文件夹中,用于实际的2种语言,当用户访问应用程序时,用户将被重定向到其中任何一种语言。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM