Laravel 5.0 文件夹结构:公共 vs. 资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28496301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.0 folder structure: public vs. resources
提问by lesssugar
In Laravel 4.2, I used publicfolder to store all my CSS, JS, images and uploads. Currently, there's a new resourcesfolder with assetsfolder in it coming with Laravel 5.0 installation:
在 Laravel 4.2 中,我使用公共文件夹来存储我所有的 CSS、JS、图像和上传。目前,Laravel 5.0 安装中有一个新的资源文件夹,其中包含资产文件夹:
/public
/resources/assets
/公共
/资源/资产
This is confusing to me, especially because resourcesalso holds viewsin it.
这让我感到困惑,尤其是因为资源中也包含视图。
Via Laravel's upgrade guide (4.2 to 5.0):
通过 Laravel 的升级指南(4.2 到 5.0):
Copy your application's public assets from your 4.2 application's publicdirectory to your new application's public directory.
将应用程序的公共资产从 4.2 应用程序的公共目录复制 到新应用程序的公共目录。
and further:
并进一步:
You may move your Sass, Less, or CoffeeScript to any location you wish. The resources/assetsdirectory could be a good default location.
您可以将 Sass、Less 或 CoffeeScript 移动到您希望的任何位置。该资源/资产目录可能是一个很好的默认位置。
Question:What is the actual difference between publicand resourcesfolders in Laravel 5.0 folder structure?
问:Laravel 5.0 文件夹结构中public和resources文件夹的实际区别是什么?
回答by lukasgeiter
The big difference here is that everything in public
is... well public. resources
aren't. What you put in where is up to you.
这里最大的不同在于,里面的所有东西public
都是......公开的。resources
不是。你把什么放在哪里取决于你。
Generally you would have everything the browser needs to access directly in the public directory. Which usually means: JavaScript, CSS, images, maybe some videos or audio files.
通常,您将拥有浏览器需要直接访问的公共目录中的所有内容。这通常意味着:JavaScript、CSS、图像,可能还有一些视频或音频文件。
resources/assets
is meant for things that have to be compiled or minified first. So you would have a few LESS or SASS files in resources/assets
and they would get compiled and minified into one CSS file that's put in the public
directory.
resources/assets
用于必须首先编译或缩小的内容。所以你会有一些 LESS 或 SASS 文件resources/assets
,它们会被编译并缩小到一个放在public
目录中的 CSS 文件。
回答by baao
Laravel elixir, by default uses the /resources/assets folder as the base directory for scripts to be compiled, minified and so on. So you should put your raw sass, less, coffeescript, js and css files in there to let elixir do it's work. A good place for the files you are using is the public folder.
Laravel elixir,默认使用 /resources/assets 文件夹作为脚本编译、压缩等的基本目录。所以你应该把你的原始 sass、less、coffeescript、js 和 css 文件放在那里,让 elixir 完成它的工作。您正在使用的文件的一个好地方是公共文件夹。
When working this way, you can have all your files concatenated and minified with gulp and less effort. Simply include them from your public folder.
以这种方式工作时,您可以使用 gulp 和更少的工作量来连接和缩小所有文件。只需从您的公用文件夹中包含它们。
回答by sebjwallace
You can think of them as being separate folders for development and production. In resources you have all your development files that'll not ship off into production (SASS, Coffeescript, Babel, Jade, etc). But when they're compiled (or piped through something like Gulp) you can configure them to output to public, the production folder.
您可以将它们视为用于开发和生产的单独文件夹。在资源中,您拥有所有不会投入生产的开发文件(SASS、Coffeescript、Babel、Jade 等)。但是当它们被编译(或通过 Gulp 之类的东西进行管道传输)时,您可以将它们配置为输出到 public,即生产文件夹。
回答by Sonu Yadav
In laravel public folder is best for Image, CSS, and Javascripts. In public folder we can use for uploaded images, videos, text files etc.
在 laravel 中的 public 文件夹最适合 Image、CSS 和 Javascripts。在公共文件夹中,我们可以用于上传图片、视频、文本文件等。