本文介绍了前端javascript文件放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于 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.

  1. 根据表达式生成器,它会创建一个app.js文件作为主条目,因此具有与入口点app.js相同名称的app文件夹看起来有点奇怪.

  1. According to express-generator, it creates an app.js file as the main entry and thus it looks a little bit strange to have an app folder with same name of the entry point app.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文件放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 03:25