我正在尝试将 ExpressJS 与 AngularJS 安装的 Angular 脚手架版本一起使用。自耕农发电机。我更喜欢使用 Yeoman 团队创建的脚手架版本,而不是使用 angular-fullstack或express版本。因此,我在项目中的服务器文件夹中手动安装了 Express JS。
-app //Angular files are here
-server //Node JS files are here
我认为当前正在使用连接服务器而不是 Express。有没有办法将 grunt 文件更改为需要 Express?
我认为这是我的 gruntfile.js 中的相关代码:
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect().use(
'/app/styles',
connect.static('./app/styles')
),
connect.static(appConfig.app)
];
}
}
}
最佳答案
配置
通过适当修改项目文件,可以根据您的需要进一步调整 Yeoman 生成的项目。
您可以通过向 bower.json
添加 appPath
属性来更改应用程序目录。例如,如果您想轻松地与 Express.js
集成,您可以添加以下内容:
{
"name": "yo-test",
"version": "0.0.0",
...
"appPath": "public"
}
这将导致 Yeoman 生成的客户端文件被公开。
请注意,您还可以通过在启动生成器时添加 --appPath
选项来实现相同的结果:
yo Angular [应用程序名称] --appPath=public
我想说,您在生成项目方面做得太过分了,请仔细阅读文档以获取更多详细信息。
关于angularjs - 使用 Express 服务器和 Yeoman 生成器搭建的 AngularJS 脚手架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29022717/