问题描述
我正在开发基于 express 的Web应用程序,我开始遵循.
I am developing an express based web application and I started following the application skeleton built by express-generator.
接下来,我将 webpack 添加到我的项目中,以捆绑客户端资产.
Next, I added to my project webpack to bundle the client side assets.
现在我不确定将前端javascript文件放置在/src
还是/app
文件夹中?
Now I am not sure where to place the front-end javascript files, if in a /src
or /app
folder?
实际上,我在app.js
,/lib
,/src
和/app
文件夹之间处于困境.
In truth, I am in a dilemma between, app.js
, /lib
, /src
and /app
folders.
-
根据表达式生成器,它会创建一个
app.js
文件作为主条目,因此具有与入口点app.js
相同名称的app
文件夹看起来有点奇怪.
According to express-generator, it creates an
app.js
file as the main entry and thus it looks a little bit strange to have anapp
folder with same name of the entry pointapp.js
.
webpack使用手册建议使用/src
文件夹放置javascript文件.但是我认为/src
不应该专门用于前端javascript,另一方面,我不想将服务器和前端javascript文件混在同一文件夹中.
webpack usage manual suggests a /src
folder to place javascript files. But I think /src
should not be exclusively for front-end javascripts and on the other hand, I would not like to mix both server and front-end javascript files in same folder.
此外,对问题 Node.js项目的文件夹结构的已接受答案与前一个相反.点,因为它指出:
Moreover, the Accepted Answer to the question Folder structure for a Node.js project, contradicts the previous point because it states:
所以,我认为/src
并不是放置前端javscript文件的更好选择,并且根据对问题,我将遵循建议的结构:
So, I think that maybe /src
is not the better option to place front-end javscript files and according to the Accepted answer to the question Node.js project naming conventions for files & folders I would follow the proposed structure:
/app - front-end javascript files
/bin - helper scripts
/lib - back-end express files
但是具有相同名称的文件夹/app
和文件app.js
可以吗?此外,/app
与前端相关,app.js
与后端相关.
But is it ok to have a folder /app
and a file app.js
with same name? Furthermore, /app
is related with front-end and app.js
with back-end.
推荐答案
我建议您将主文件从app.js
重命名为index.js
,并将建议的结构保留在Node.js项目文件的命名约定&文件夹:
I would suggest you to just rename your main file from app.js
to index.js
and keep the structure proposed in Node.js project naming conventions for files & folders:
/app - front-end javascript files
/bin - helper scripts
/lib - back-end express files
因此,与前端相关的/app
文件夹与作为后端入口点的index.js
之间没有更多的误导.
Thus, there is no more misleading between /app
folder related to front-end and the index.js
, which is the back-end entry point.
这篇关于前端javascript文件放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!