Laravel website project directory structure planning

Source: Internet
Author: User
Tags php framework composer install

I've recently learned a lot by using Laravel, the PHP framework, to get an overview of the framework's directory structure.

Install the Package Manager first:

PHP part of course with composer, installed in the global directory convenient point.

Front-end part, I did not choose NPM but to use more "advanced" yarn.

You can open Laravel's official documentation for reference.

I write this article is to understand their own development ideas, before I directly to the entire Web site project from the server to copy to their own computer to write, but this need to copy too many things, most of which I do not move the third party library. So I have to figure out how to do this, I can keep my computer and the server's files synchronized with the least downloaded files. This also facilitates code testing on a local server, without having to synchronize local modifications to the server each time, and then test the results from the server.

The general idea is to only synchronize the Package manager's configuration files and then read them locally through the Package Manager to download the same third-party library as the server.

1. Dependency of PHP

After installing the Larvel, the root directory will have composer for the third-party Library vendor folder, the contents of this folder can be added. Gitignore, in fact laravel default Gitignore do the same. We just need to add Composer.json to Git to synchronize the libraries that PHP uses.

In this way, the repo from git pull down, only need to execute composer install to get the same library as the server.

2. Front-end Project dependencies

The front-end library will be placed in the Laravel root directory under the Node_modules directory (hereinafter referred to as NM), this nm should be placed in Gitignore, not sync to git, only sync Packages.json and Yarn.lock (If you use yarn to replace NPM).

In the local repo, only yarn install is required to obtain the same library as the server.

3. Storage of front-end resources

Laravel also has two folders public and resources, originally I have been the CSS JS and other resource files are placed directly in the public folder, but it seems inappropriate to do so, In particular, using Scss/sass and typescript, this requires compiling to generate CSS/JS files that the actual browser uses.

It is reasonable to put SCSS and typescript in the resources, and the final document translated will be placed under public. This allows the browser to access the final Css/js file, but not the source file. This is also handy if the translation is minify. In short, the source files are stripped out of the public directory to prevent user access.

Operations such as translation can use Webpack and can also implement more advanced features such as modularity.

Laravel website project directory structure planning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.