On the project I am joining this is the architecture for the node_packages:

在我加入的项目中,这是node_packages的架构:

|- Django project
|-- app1
|-- app2
|-- node_modules
|--- foundation-sites
|--- grunt
|-- static
|--- css
|--- images
|--- js
|--urls.py
|--settings.py
|--package.json

I personally think node_packages should be in the static under the js folder as well as the package.json like so:

我个人认为node_packages应该放在js文件夹和包下面的静态文件夹中。json:一样

|- Django project
|-- app1
|-- app2
|-- static
|--- css
|--- images
|--- js
|---- node_modules
|----- foundation-sites
|----- grunt
|---- packages.json
|--urls.py
|--settings.py

is there a difference? which is best practice? why?

有区别吗?最佳实践是什么?为什么?

3 个解决方案

#1


17

I understand your thinking of wanting to keep all the javascript related files in one place, but here are a couple of reasons you might want to keep the node_modules folder and the package.json file out of a Django app's static directory.

我理解您希望将所有与javascript相关的文件保存在一个地方的想法,但这里有两个原因,您可能希望保留node_modules文件夹和包。json文件来自Django应用程序的静态目录。

  1. You'll likely end up statically serving files that aren't meant to be. If the node_modules folder exists in your production environment, running collectstatic will have to check that it's in sync every time, which can be slow due to nodes nested dependency structure. And assuming you have a build step to bundle and transpile your JS, if those source files are within static, they too will be served as static files, for no reason.
  2. 最后,您可能会静态地处理不应该是的文件。如果node_modules文件夹存在于您的生产环境中,那么运行collectstatic将不得不每次检查它是否处于同步状态,这可能会由于节点嵌套依赖结构而导致速度缓慢。假设您有一个构建步骤来捆绑和传输您的JS,如果这些源文件在静态文件中,它们也将毫无理由地作为静态文件使用。
  3. You might want to use node for more than just your JavaScript build process. I see you're using Grunt, and you may want to use it to for more than your JavaScript needs, like minifying your css, or running a proxy server around your Django dev server that auto-reloads your browser when files change or the Django server restarts. With this in mind, it might make more sense to think of Node.js as a tool in your build process that could touch any part of your project, the bundling/transpiling of JavaScript being only one part of that.
  4. 您可能想要使用node而不仅仅是JavaScript构建过程。我看到您在使用Grunt,您可能想要使用它来满足您的JavaScript需求,比如缩小您的css,或者在Django dev服务器上运行一个代理服务器,当文件更改或Django服务器重启时自动重新加载您的浏览器。考虑到这一点,考虑Node可能更有意义。js作为构建过程中可以触及项目任何部分的工具,JavaScript的打包/转换只是其中的一部分。

更多相关文章

  1. 如何使用python 3检查文件夹是否包含文件
  2. 如何使用未受标头影响的python导入csv文件,其中第一列为非数值
  3. python在windows中的文件路径问题
  4. 套接字。接受错误24:对许多打开的文件
  5. python如何将一个txt文件里的转化为相应字典
  6. Python之错误异常和文件处理
  7. python解析json文件读取Android permission说明
  8. python 之 logger日志 字典配置文件
  9. [置顶] Python + C/C++ 嵌入式编程(1):多维数组Numpy.Array(

随机推荐

  1. Android(安卓)Animation总结
  2. linux基础教程--安装Android SDK
  3. android之View属性
  4. cocos2d-x3.0beta版+NDK-r9b在android上
  5. android点击邮箱链接跳转发送
  6. Android 深入解析selector
  7. Android ScrollView 判断到顶到底,和设置
  8. Android:开发常用的名令集锦
  9. Android Touch事件分发机制学习
  10. Android隐式启动Activity匹配详解:Action,c