Package Data | |
---|---|
Maintainer Username: | prwlr |
Package Create Date: | 2017-08-19 |
Package Last Update: | 2017-08-27 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-17 03:01:28 |
Package Statistics | |
---|---|
Total Downloads: | 38 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 5 |
Total Watchers: | 2 |
Total Forks: | 1 |
Total Open Issues: | 0 |
This is a Laravel template I use for my own projects.
The most important change is that it removes all of Laravel Mix configuration and adds new webpack config files. I tried using Laravel Mix for some projects but it just didn't feel right. I didn't like how everything was configured, it took way too long to compile sometimes and I just felt like I had no control.
I took the new configuration files from the vue-webpack template and integrated them with Laravel. The workflow feels very nice and fast now.
I also rewrote all the views (even the ones generated by the Auth command) in Vue. The blade templates only define a mount point that maps automatically to a Vue component of the same name defined in the resources/assets/js/pages
folder. I will explain more about this in a section below.
At the end there is a lot going on and it's really opinionated, but you can see all of the configuration files and change them if you need to. Or maybe you could just give it a try as it is and tell me what you think!
It's really easy to get up and running. Just follow these steps:
composer create-project --prefer-dist prwlr/laravue project-name
.yarn
or npm install
to install all dependencies..env
file there is a line that reads APP_URL=http://localhost
. Change that variable to whatever your application url is. This is important for development since paths to assets will be constructed using this url. For example for the homestead default url it would look like APP_URL=http://homestead.app
. If you app is running in a specific port just put it as it is, for example if your app is running on localhost at port 8000, just put APP_URL=http://localhost:8000
.yarn dev
or npm run dev
to start working on your project.The command will try to open a browser automatically pointing to your project's url. Sometimes it won't be able to, for example when running with vagrant, so just open it manually.
You can also use the php artisan make:auth
command which I modified to generate the same pages you would expect, but showcasing some Vue components instead.
I'll try to list everything that has been included in the template.
.js
files or using .vue
files. I prefer the JSX syntax since I feel I have more control. It also feels more natural since I've been writing React for quite a while. If you want to use .vue
files syntax, you will have to mount the components yourself. I will add automatic mounting of those later on..scssm
file to handle its own styles. This file extension was defined by me to tell webpack to process this file with SCSS and CSS Modules. It's a nice combo since you have scoped selectors, and can also make use of your variables and mixins importing them from your sass folder.I'll just copy most of the descriptions from the Vuejs Webpack template since this is the template I merged with Laravel. If you want to know anything else about the tasks, about the folder structure or how to change or extend anything refer to their docs.
yarn dev || npm run dev
: First-in-class development experience.
APP_URL
(It will try to open it automatically).vue-loader
for single file Vue components is also available.yarn build || npm run build
: Production ready build.
base.blade.php
is auto-generated with proper URLs to these generated assets.There is a command for testing which is yarn test || npm run test
, but it doesn't work for now. Still not sure how to handle testing for Vue Components using the JSX syntax. You can consider it WIP.
There is a folder called client_config
which has some objects needed for the build and dev configurations. Most of them you don't need to worry about, but there are some that could be useful. For example you can set cssSourceMap
to true
to generate source maps in development. Is not activated by default because relative paths are "buggy" (A more detailed explanation can be found in a comment in the file). To know more about the options refer to the vuejs-templates webpack docs.
In the .env file you can also set a the DEV_POLLING
to TRUE
in order to enable polling in the webpack dev config. This is useful when running the project with Homestead for example.
You can also change the DEV_PORT
variable in order to change the port in which express will be running (Express is used along with webpack to serve the assets).
Laravel adds some useful stuff to a global Javascript variable called Laravel
. I added some more stuff to it like the error bag and the old inputs. There is an utils
folder where I created a file called laravel
that just pulls in the global variable and exports it. Then in my Vue components I can import it to make calls to that variable a little bit cleaner.
If a view has an specific requirement for a php variable or something that it could get from Laravel, I have created some little blade
files that I put in the resources/views/injectors
folder that serve that purpose. They just add a script that attaches the new value to the Laravel global variable. You can then include this injector in the view that should use it. You can check some examples in the views that come by default or in the views generated by the Auth command.
Since I'm using Vue to handle all the content of the views, I've defined a new category of components called page components. You can find them in the resources/assets/js/pages
folder. These components are used as the main entry points. There is a convention for connecting pages with views. All page components are created using folders with names written in Pascal Case and map automatically to a mount point or div with an id
of the same value as the name of the folder but written in Kebab Case. For example resources/assets/js/pages/ExampleTest/index.js
will mount automatically inside <div id="example-test"></div>
.
Not really. I'd just want to thank you for giving it a try or at least reading through. If you have any feedback it'd be greatly appreciated. I bet a lot of things could be improved and I'm open to discussion, so open an issue, send a pull request or message me to gianluca.prwlr@gmail.com.