Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shirshak's avatar

Referencing Root Folder In Vue Files at Laravel

I have a Vue files for another modules at laravel/packages/shirshak/books/views/routes

But I need to references them from laravel/resources/js/backend/router/index.js (normal in laravel) .

Inside that index.js I need to import that books routes? How can i do that .

I guess there is better solution than this one

import BookRoutes from ../../../../packages/shirshak/books/views/routes

Is there any better solution than this.

In Vue Cli we can use @ to reference source folder ? How can i get for laravel projects

Thanks

0 likes
1 reply
lostdreamer_nl's avatar

I believe (dont know for sure) that laravel/resources is one of the paths that will also be checked if it cannot find the file relative to the current location. So it might be that this works in your case:

import BookRoutes from ../packages/shirshak/books/views/routes

If it doesn't, you can add this to your webpack.mix.js


mix.webpackConfig({
  resolve: {
    modules: [
      path.resolve(__dirname),
      path.resolve('./node_modules/'),
      path.resolve('./resources/')
    ]
  }
});

After that change, any relative package you import, will go in the order of:

  • relative to current file
  • relative to where webpack.mix.js is
  • relative to node_modules
  • relative to resources

So after that change you should be able to do:

import BookRoutes from packages/shirshak/books/views/routes

Please or to participate in this conversation.