Boilerplate w/ Laravel example: https://github.com/jpalala/laravel-customjs-boilerplate
Last active
June 15, 2022 06:05
-
-
Save jpalala/50f118f6daea7defd8b95e6006a23dbe to your computer and use it in GitHub Desktop.
how to deploy frontend js app to resources views and include it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
WELCOME_FILE = "resources/views/welcome.blade.php" | |
FRONTEND_FILE = "index.phtml" | |
cp dist/index.html "public/$FRONTEND_FILE" | |
# create public folders for css and js: | |
mkdir public/css && cp -Rf dist/css/* public/css | |
mkdir public/js && cp -Rf dist/js/* public/js | |
# append the code to to blade file | |
# echo "\n @php | |
# \n include_once(base_path() . '/public/index.phtml'); | |
# \n @endphp" >> $WELCOME_FILE | |
# alternative -> https://github.com/wewowweb/laravel-mix-svelte |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// <!-- file: public/index.php (default laravel public/index.php file) --> | |
use Illuminate\Contracts\Http\Kernel; | |
use Illuminate\Http\Request; | |
define('LARAVEL_START', microtime(true)); | |
$parsed_url = parse_url($_SERVER['REQUEST_URI']); | |
$path = $parsed['path']; | |
$paths = explode('/', ltrim($parse_url['path'], '/')); | |
$first_path = substr($fpaths[0], 0, 3); // /api ba? | |
// only run laravel-related code if it is `/api` related or the front page (views/welcome.blade.php = first page) | |
// otherwise if its not an api page or the front page, the matched route view should not be served | |
if(first_path == 'api' && ($first_path == '')) | |
{ | |
/* | |
|-------------------------------------------------------------------------- | |
| Check If The Application Is Under Maintenance | |
|-------------------------------------------------------------------------- | |
| | |
| If the application is in maintenance / demo mode via the "down" command | |
| we will load this file so that any pre-rendered content can be shown | |
| instead of starting the framework, which could cause an exception. | |
| | |
*/ | |
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) { | |
require $maintenance; | |
} | |
/* | |
|-------------------------------------------------------------------------- | |
| Register The Auto Loader | |
|-------------------------------------------------------------------------- | |
| | |
| Composer provides a convenient, automatically generated class loader for | |
| this application. We just need to utilize it! We'll simply require it | |
| into the script here so we don't need to manually load our classes. | |
| | |
*/ | |
require __DIR__.'/../vendor/autoload.php'; | |
/* | |
|-------------------------------------------------------------------------- | |
| Run The Application | |
|-------------------------------------------------------------------------- | |
| | |
| Once we have the application, we can handle the incoming request using | |
| the application's HTTP kernel. Then, we will send the response back | |
| to this client's browser, allowing them to enjoy our application. | |
| | |
*/ | |
$app = require_once __DIR__.'/../bootstrap/app.php'; | |
$kernel = $app->make(Kernel::class); | |
$response = $kernel->handle( | |
$request = Request::capture() | |
)->send(); | |
$kernel->terminate($request, $response); | |
} else { | |
die('invalid route'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This includes the frontend file. You can remove this comment. The below is appended to this file by the deploy script.. | |
// include any ENV or local variables that you might need in your frontend app | |
?> | |
<?php include_once(base_path() . '/public/index.phtml'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment