jandk4014's avatar

Ionic www hosted in Laravel

I have an Ionic app running just fine on the mobile side. I performed a valet park inside of the www directory of my Ionic app to test out the site. The valet worked!

What I'd like to do is take the contents of my Ionic www directory and add that to my Laravel project where my normal site is hosted.

How do I do that?

0 likes
3 replies
bobbybouwmann's avatar

What do you mean by adding it to your laravel project exactly?

I suppose you want to go to example.com/ionic or something in that directory to actually see the content of the www directory. In that case you can create a directory called ionic in the public directory and move everything from the www to there.

If you want it to use the same url as your laravel application you might have a harder time making this happen. Laravel has a index.php in the public directory which catches all requests. From there it goes to the router and into the application. You can probably do something in the router to make this work, but a sub directory is by far the easiest solution!

1 like
jandk4014's avatar

@bobbybouwmann - You're rather right; that's what I did. What I ended up doing was performing an ionic build --prod. This did build everything for my PWA under a www/pwa folder in the project. Side note, I modified my angular.json file to set that output path.

I then just copied that entire directory (pwa) to the public directory of my Laravel project.

I did have to modify my public/pwa/index.html file. I correctly changed

  • <base href="/pwa/" />
  • And added the /pwa/... to all the /assets/ items.
  • I also added a route. Don't know if that's necessary but it worked for me.
Route::get('/pwa', function() {
   View::addExtension('html', 'php');
   return View::make('pwa');
});

Now I know that this process of deployment is manual.

Does anybody have a suggestion how I can script this so when I make changes to Ionic/Angular by code is deployed to my Laravel source?

bobbybouwmann's avatar

Well that depends on how you currently deploy your Laravel project?

You can put that www in version control and then it should be deployed right away if you use git for deployments as an example

Please or to participate in this conversation.