django npm和节点包体系结构 [英] django npm and node packages architecture

查看:100
本文介绍了django npm和节点包体系结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我要加入的项目中,这是node_packages的体系结构:

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

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

我个人认为node_packages应该位于js文件夹以及package.json下的静态位置,如下所示:

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

|- 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?

推荐答案

我了解您想将所有与javascript相关的文件都保存在一个地方的想法,但是有以下两个原因可能会让您保存node_modules文件夹和Django应用程序static目录中的package.json文件.

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.

  1. 您可能最终会以静态方式提供本来不是本来应该提供的文件.如果生产环境中存在node_modules文件夹,则运行collectstatic时必须检查其是否在每次都同步,由于节点嵌套依赖项结构,这可能会很慢.并假设您有构建步骤来捆绑和翻译JS,如果这些源文件在static中,则它们也将毫无理由地用作静态文件.
  2. 您可能希望将节点不仅用于JavaScript生成过程.我看到您正在使用Grunt,并且您可能希望将其用于满足JavaScript的更多需求,例如最小化您的css,或在Django开发服务器周围运行代理服务器,当文件更改或Django服务器重新启动时,该代理服务器会自动重新加载浏览器.考虑到这一点,在构建过程中将Node.js视为可以触及项目任何部分的工具可能更有意义,JavaScript的捆绑/移植只是其中的一部分.
  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. 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.

这篇关于django npm和节点包体系结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆