Have Laravel load an alternate public folder on development machine

258 views Asked by At

We have a build script that minimizes javascript/css and then copies it into the public folder.

What I'd like is for development boxes to load files from the app folder, where the unminimized scripts are stored on dev boxes, but still run the minimized scripts on production.

WHAT I'VE TRIED SO FAR:

-Changing the public path:

if (App::environment() == 'development') {
    App::bind('path.public', function () {
        return app_path() . '/unminimized';
    });
}

This works for anywhere we use public_path(), but the front-end programmer uses relative paths, not URL::asset() (or whatnot), to load javascript (we use a framework, so this isn't easy to change). His javascript is still loaded from the public folder

-Changing nginx: I've tried changing the root_path in nginx from /website/public to /website/code. This loads the javascript correctly, but then my routes don't fire.

Does anyone have any ideas how to accomplish this?

2

There are 2 answers

0
Nicholas Hall On BEST ANSWER

If you modify nginx to point to /website/code on the dev box and then copy the index.php file from /website/public to /website/code it should fix your routes.

You will need to modify the following lines in index.php:

require __DIR__.'/../bootstrap/autoload.php';

and

$app = require_once __DIR__.'/../bootstrap/start.php';

to match the new location so they can include those files correctly.

3
marblewraith On

Seems rather round about...

Lemme see if i've something right first, are you writing your stuff in pre-compiler languages (scss/sass/less/coffeescript)?

If so then it shouldn't matter what you're doing with the uncompressed stuff since:

  1. You should be testing your minified code before pushing to deploy
  2. You should not be deploying both your minified code and your dev versions

Easiest way i see you solving this problem is using something like gulp-inject write a gulp task that you can pass a flag --dev or --prod which will manage which versions of files are inserted into your blade templates (have it default to --dev).

Naturally it would also be advantagous to write a similar task to undo those changes.

Then if you want to take it a step further have a dedicated VCS and manage your dev and production versions in different 'branches'.