Laravel mix generates relative paths












0














On production, to load my assets I use for example:



<link href="{{ mix('/css/app.css') }}" rel="stylesheet">


and expect to see when compiled:



<link href="https://example.com/css/app.083fd04ba374238b03b23e742c997718.css" rel="stylesheet">


However I am just seeing the relative path:



<link href="/css/app.083fd04ba374238b03b23e742c997718.css" rel="stylesheet">


webpack.mix.js:



mix
.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.sass('resources/assets/sass/print.scss', 'public/css')
.copy([
'node_modules/bootstrap-sass/assets/fonts/bootstrap',
'node_modules/font-awesome/fonts',
], 'public/fonts')
.sourceMaps();

if (mix.config.inProduction) {
mix
.version()
.disableNotifications();
} else {
//
}


On latest version of Laravel (5.4.21). Using nginx, forcing https on Ubuntu 16.04. No idea why the paths are not full, but relative.



EDIT: I am also seeing the same behavior locally if I try to use mix vs asset, without https. Protocol seems not matter here actually.










share|improve this question





























    0














    On production, to load my assets I use for example:



    <link href="{{ mix('/css/app.css') }}" rel="stylesheet">


    and expect to see when compiled:



    <link href="https://example.com/css/app.083fd04ba374238b03b23e742c997718.css" rel="stylesheet">


    However I am just seeing the relative path:



    <link href="/css/app.083fd04ba374238b03b23e742c997718.css" rel="stylesheet">


    webpack.mix.js:



    mix
    .js('resources/assets/js/app.js', 'public/js')
    .sass('resources/assets/sass/app.scss', 'public/css')
    .sass('resources/assets/sass/print.scss', 'public/css')
    .copy([
    'node_modules/bootstrap-sass/assets/fonts/bootstrap',
    'node_modules/font-awesome/fonts',
    ], 'public/fonts')
    .sourceMaps();

    if (mix.config.inProduction) {
    mix
    .version()
    .disableNotifications();
    } else {
    //
    }


    On latest version of Laravel (5.4.21). Using nginx, forcing https on Ubuntu 16.04. No idea why the paths are not full, but relative.



    EDIT: I am also seeing the same behavior locally if I try to use mix vs asset, without https. Protocol seems not matter here actually.










    share|improve this question



























      0












      0








      0







      On production, to load my assets I use for example:



      <link href="{{ mix('/css/app.css') }}" rel="stylesheet">


      and expect to see when compiled:



      <link href="https://example.com/css/app.083fd04ba374238b03b23e742c997718.css" rel="stylesheet">


      However I am just seeing the relative path:



      <link href="/css/app.083fd04ba374238b03b23e742c997718.css" rel="stylesheet">


      webpack.mix.js:



      mix
      .js('resources/assets/js/app.js', 'public/js')
      .sass('resources/assets/sass/app.scss', 'public/css')
      .sass('resources/assets/sass/print.scss', 'public/css')
      .copy([
      'node_modules/bootstrap-sass/assets/fonts/bootstrap',
      'node_modules/font-awesome/fonts',
      ], 'public/fonts')
      .sourceMaps();

      if (mix.config.inProduction) {
      mix
      .version()
      .disableNotifications();
      } else {
      //
      }


      On latest version of Laravel (5.4.21). Using nginx, forcing https on Ubuntu 16.04. No idea why the paths are not full, but relative.



      EDIT: I am also seeing the same behavior locally if I try to use mix vs asset, without https. Protocol seems not matter here actually.










      share|improve this question















      On production, to load my assets I use for example:



      <link href="{{ mix('/css/app.css') }}" rel="stylesheet">


      and expect to see when compiled:



      <link href="https://example.com/css/app.083fd04ba374238b03b23e742c997718.css" rel="stylesheet">


      However I am just seeing the relative path:



      <link href="/css/app.083fd04ba374238b03b23e742c997718.css" rel="stylesheet">


      webpack.mix.js:



      mix
      .js('resources/assets/js/app.js', 'public/js')
      .sass('resources/assets/sass/app.scss', 'public/css')
      .sass('resources/assets/sass/print.scss', 'public/css')
      .copy([
      'node_modules/bootstrap-sass/assets/fonts/bootstrap',
      'node_modules/font-awesome/fonts',
      ], 'public/fonts')
      .sourceMaps();

      if (mix.config.inProduction) {
      mix
      .version()
      .disableNotifications();
      } else {
      //
      }


      On latest version of Laravel (5.4.21). Using nginx, forcing https on Ubuntu 16.04. No idea why the paths are not full, but relative.



      EDIT: I am also seeing the same behavior locally if I try to use mix vs asset, without https. Protocol seems not matter here actually.







      laravel laravel-mix






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 5 '17 at 23:39

























      asked May 5 '17 at 23:34









      Jared Eitnier

      3,978951103




      3,978951103
























          3 Answers
          3






          active

          oldest

          votes


















          1














          If you check out the source, that is how it is designed to work. You could always write your own helper.



          You need to add this to a helpers file.



          use IlluminateSupportStr;
          use IlluminateSupportHtmlString;

          if (! function_exists('mixUrl')) {
          /**
          * Get the path to a versioned Mix file.
          *
          * @param string $path
          * @param string $manifestDirectory
          * @param string $baseUrl
          * @return IlluminateSupportHtmlString
          *
          * @throws Exception
          */
          function mixUrl($path, $manifestDirectory = '', $baseUrl = null)
          {
          static $manifest;

          if (! starts_with($path, '/')) {
          $path = "/{$path}";
          }

          if ($manifestDirectory && ! starts_with($manifestDirectory, '/')) {
          $manifestDirectory = "/{$manifestDirectory}";
          }

          if (file_exists(public_path($manifestDirectory.'/hot'))) {
          return new HtmlString("//localhost:8080{$path}");
          }

          if (! $manifest) {
          if (! file_exists($manifestPath = public_path($manifestDirectory.'/mix-manifest.json'))) {
          throw new Exception('The Mix manifest does not exist.');
          }

          $manifest = json_decode(file_get_contents($manifestPath), true);
          }

          if (!is_null($baseUrl)){
          if (strlen($baseUrl) > 1 && Str::endsWith($baseUrl, '/')) {
          $baseUrl = substr($baseUrl, 0, -1);
          }
          return new HtmlString($baseUrl . $manifestDirectory . $manifest[$path]);
          }

          if (! array_key_exists($path, $manifest)) {
          throw new Exception(
          "Unable to locate Mix file: {$path}. Please check your ".
          'webpack.mix.js output paths and try again.'
          );
          }

          return new HtmlString($manifestDirectory.$manifest[$path]);
          }
          }


          called from blade like



          <script src="{{ mixUrl('/css/app.css', '', 'http://example.com') }}"></script>





          share|improve this answer





















          • Thanks man, this is exactly what I was going to end up doing anyway. Seems kind of odd that this is the functionality but either way I got it working.
            – Jared Eitnier
            May 7 '17 at 21:35










          • Glad it helped! After working with Laravel for a while, once it doesn't make sense I head to the source.
            – whoacowboy
            May 8 '17 at 10:10



















          9














          The best way to handle this is to use the asset() helper to prepend your APP_URL.



          <script src="{{ asset(mix('css/app.css')) }}"></script>





          share|improve this answer





















          • Works prefectly, no need of custom helper. This should be the accepted answer.
            – bgaze
            Oct 4 at 10:13





















          0














          The best way is to use asset() helper. But there is another way to handle this by using url() or secure_url() helper



          <script src="{{ url(mix('css/app.css')) }}"></script>


          or



          <script src="{{ secure_url(mix('css/app.css')) }}"></script>





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43815086%2flaravel-mix-generates-relative-paths%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            If you check out the source, that is how it is designed to work. You could always write your own helper.



            You need to add this to a helpers file.



            use IlluminateSupportStr;
            use IlluminateSupportHtmlString;

            if (! function_exists('mixUrl')) {
            /**
            * Get the path to a versioned Mix file.
            *
            * @param string $path
            * @param string $manifestDirectory
            * @param string $baseUrl
            * @return IlluminateSupportHtmlString
            *
            * @throws Exception
            */
            function mixUrl($path, $manifestDirectory = '', $baseUrl = null)
            {
            static $manifest;

            if (! starts_with($path, '/')) {
            $path = "/{$path}";
            }

            if ($manifestDirectory && ! starts_with($manifestDirectory, '/')) {
            $manifestDirectory = "/{$manifestDirectory}";
            }

            if (file_exists(public_path($manifestDirectory.'/hot'))) {
            return new HtmlString("//localhost:8080{$path}");
            }

            if (! $manifest) {
            if (! file_exists($manifestPath = public_path($manifestDirectory.'/mix-manifest.json'))) {
            throw new Exception('The Mix manifest does not exist.');
            }

            $manifest = json_decode(file_get_contents($manifestPath), true);
            }

            if (!is_null($baseUrl)){
            if (strlen($baseUrl) > 1 && Str::endsWith($baseUrl, '/')) {
            $baseUrl = substr($baseUrl, 0, -1);
            }
            return new HtmlString($baseUrl . $manifestDirectory . $manifest[$path]);
            }

            if (! array_key_exists($path, $manifest)) {
            throw new Exception(
            "Unable to locate Mix file: {$path}. Please check your ".
            'webpack.mix.js output paths and try again.'
            );
            }

            return new HtmlString($manifestDirectory.$manifest[$path]);
            }
            }


            called from blade like



            <script src="{{ mixUrl('/css/app.css', '', 'http://example.com') }}"></script>





            share|improve this answer





















            • Thanks man, this is exactly what I was going to end up doing anyway. Seems kind of odd that this is the functionality but either way I got it working.
              – Jared Eitnier
              May 7 '17 at 21:35










            • Glad it helped! After working with Laravel for a while, once it doesn't make sense I head to the source.
              – whoacowboy
              May 8 '17 at 10:10
















            1














            If you check out the source, that is how it is designed to work. You could always write your own helper.



            You need to add this to a helpers file.



            use IlluminateSupportStr;
            use IlluminateSupportHtmlString;

            if (! function_exists('mixUrl')) {
            /**
            * Get the path to a versioned Mix file.
            *
            * @param string $path
            * @param string $manifestDirectory
            * @param string $baseUrl
            * @return IlluminateSupportHtmlString
            *
            * @throws Exception
            */
            function mixUrl($path, $manifestDirectory = '', $baseUrl = null)
            {
            static $manifest;

            if (! starts_with($path, '/')) {
            $path = "/{$path}";
            }

            if ($manifestDirectory && ! starts_with($manifestDirectory, '/')) {
            $manifestDirectory = "/{$manifestDirectory}";
            }

            if (file_exists(public_path($manifestDirectory.'/hot'))) {
            return new HtmlString("//localhost:8080{$path}");
            }

            if (! $manifest) {
            if (! file_exists($manifestPath = public_path($manifestDirectory.'/mix-manifest.json'))) {
            throw new Exception('The Mix manifest does not exist.');
            }

            $manifest = json_decode(file_get_contents($manifestPath), true);
            }

            if (!is_null($baseUrl)){
            if (strlen($baseUrl) > 1 && Str::endsWith($baseUrl, '/')) {
            $baseUrl = substr($baseUrl, 0, -1);
            }
            return new HtmlString($baseUrl . $manifestDirectory . $manifest[$path]);
            }

            if (! array_key_exists($path, $manifest)) {
            throw new Exception(
            "Unable to locate Mix file: {$path}. Please check your ".
            'webpack.mix.js output paths and try again.'
            );
            }

            return new HtmlString($manifestDirectory.$manifest[$path]);
            }
            }


            called from blade like



            <script src="{{ mixUrl('/css/app.css', '', 'http://example.com') }}"></script>





            share|improve this answer





















            • Thanks man, this is exactly what I was going to end up doing anyway. Seems kind of odd that this is the functionality but either way I got it working.
              – Jared Eitnier
              May 7 '17 at 21:35










            • Glad it helped! After working with Laravel for a while, once it doesn't make sense I head to the source.
              – whoacowboy
              May 8 '17 at 10:10














            1












            1








            1






            If you check out the source, that is how it is designed to work. You could always write your own helper.



            You need to add this to a helpers file.



            use IlluminateSupportStr;
            use IlluminateSupportHtmlString;

            if (! function_exists('mixUrl')) {
            /**
            * Get the path to a versioned Mix file.
            *
            * @param string $path
            * @param string $manifestDirectory
            * @param string $baseUrl
            * @return IlluminateSupportHtmlString
            *
            * @throws Exception
            */
            function mixUrl($path, $manifestDirectory = '', $baseUrl = null)
            {
            static $manifest;

            if (! starts_with($path, '/')) {
            $path = "/{$path}";
            }

            if ($manifestDirectory && ! starts_with($manifestDirectory, '/')) {
            $manifestDirectory = "/{$manifestDirectory}";
            }

            if (file_exists(public_path($manifestDirectory.'/hot'))) {
            return new HtmlString("//localhost:8080{$path}");
            }

            if (! $manifest) {
            if (! file_exists($manifestPath = public_path($manifestDirectory.'/mix-manifest.json'))) {
            throw new Exception('The Mix manifest does not exist.');
            }

            $manifest = json_decode(file_get_contents($manifestPath), true);
            }

            if (!is_null($baseUrl)){
            if (strlen($baseUrl) > 1 && Str::endsWith($baseUrl, '/')) {
            $baseUrl = substr($baseUrl, 0, -1);
            }
            return new HtmlString($baseUrl . $manifestDirectory . $manifest[$path]);
            }

            if (! array_key_exists($path, $manifest)) {
            throw new Exception(
            "Unable to locate Mix file: {$path}. Please check your ".
            'webpack.mix.js output paths and try again.'
            );
            }

            return new HtmlString($manifestDirectory.$manifest[$path]);
            }
            }


            called from blade like



            <script src="{{ mixUrl('/css/app.css', '', 'http://example.com') }}"></script>





            share|improve this answer












            If you check out the source, that is how it is designed to work. You could always write your own helper.



            You need to add this to a helpers file.



            use IlluminateSupportStr;
            use IlluminateSupportHtmlString;

            if (! function_exists('mixUrl')) {
            /**
            * Get the path to a versioned Mix file.
            *
            * @param string $path
            * @param string $manifestDirectory
            * @param string $baseUrl
            * @return IlluminateSupportHtmlString
            *
            * @throws Exception
            */
            function mixUrl($path, $manifestDirectory = '', $baseUrl = null)
            {
            static $manifest;

            if (! starts_with($path, '/')) {
            $path = "/{$path}";
            }

            if ($manifestDirectory && ! starts_with($manifestDirectory, '/')) {
            $manifestDirectory = "/{$manifestDirectory}";
            }

            if (file_exists(public_path($manifestDirectory.'/hot'))) {
            return new HtmlString("//localhost:8080{$path}");
            }

            if (! $manifest) {
            if (! file_exists($manifestPath = public_path($manifestDirectory.'/mix-manifest.json'))) {
            throw new Exception('The Mix manifest does not exist.');
            }

            $manifest = json_decode(file_get_contents($manifestPath), true);
            }

            if (!is_null($baseUrl)){
            if (strlen($baseUrl) > 1 && Str::endsWith($baseUrl, '/')) {
            $baseUrl = substr($baseUrl, 0, -1);
            }
            return new HtmlString($baseUrl . $manifestDirectory . $manifest[$path]);
            }

            if (! array_key_exists($path, $manifest)) {
            throw new Exception(
            "Unable to locate Mix file: {$path}. Please check your ".
            'webpack.mix.js output paths and try again.'
            );
            }

            return new HtmlString($manifestDirectory.$manifest[$path]);
            }
            }


            called from blade like



            <script src="{{ mixUrl('/css/app.css', '', 'http://example.com') }}"></script>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 6 '17 at 10:23









            whoacowboy

            4,03042454




            4,03042454












            • Thanks man, this is exactly what I was going to end up doing anyway. Seems kind of odd that this is the functionality but either way I got it working.
              – Jared Eitnier
              May 7 '17 at 21:35










            • Glad it helped! After working with Laravel for a while, once it doesn't make sense I head to the source.
              – whoacowboy
              May 8 '17 at 10:10


















            • Thanks man, this is exactly what I was going to end up doing anyway. Seems kind of odd that this is the functionality but either way I got it working.
              – Jared Eitnier
              May 7 '17 at 21:35










            • Glad it helped! After working with Laravel for a while, once it doesn't make sense I head to the source.
              – whoacowboy
              May 8 '17 at 10:10
















            Thanks man, this is exactly what I was going to end up doing anyway. Seems kind of odd that this is the functionality but either way I got it working.
            – Jared Eitnier
            May 7 '17 at 21:35




            Thanks man, this is exactly what I was going to end up doing anyway. Seems kind of odd that this is the functionality but either way I got it working.
            – Jared Eitnier
            May 7 '17 at 21:35












            Glad it helped! After working with Laravel for a while, once it doesn't make sense I head to the source.
            – whoacowboy
            May 8 '17 at 10:10




            Glad it helped! After working with Laravel for a while, once it doesn't make sense I head to the source.
            – whoacowboy
            May 8 '17 at 10:10













            9














            The best way to handle this is to use the asset() helper to prepend your APP_URL.



            <script src="{{ asset(mix('css/app.css')) }}"></script>





            share|improve this answer





















            • Works prefectly, no need of custom helper. This should be the accepted answer.
              – bgaze
              Oct 4 at 10:13


















            9














            The best way to handle this is to use the asset() helper to prepend your APP_URL.



            <script src="{{ asset(mix('css/app.css')) }}"></script>





            share|improve this answer





















            • Works prefectly, no need of custom helper. This should be the accepted answer.
              – bgaze
              Oct 4 at 10:13
















            9












            9








            9






            The best way to handle this is to use the asset() helper to prepend your APP_URL.



            <script src="{{ asset(mix('css/app.css')) }}"></script>





            share|improve this answer












            The best way to handle this is to use the asset() helper to prepend your APP_URL.



            <script src="{{ asset(mix('css/app.css')) }}"></script>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 19 '17 at 20:29









            Devon

            22.5k42646




            22.5k42646












            • Works prefectly, no need of custom helper. This should be the accepted answer.
              – bgaze
              Oct 4 at 10:13




















            • Works prefectly, no need of custom helper. This should be the accepted answer.
              – bgaze
              Oct 4 at 10:13


















            Works prefectly, no need of custom helper. This should be the accepted answer.
            – bgaze
            Oct 4 at 10:13






            Works prefectly, no need of custom helper. This should be the accepted answer.
            – bgaze
            Oct 4 at 10:13













            0














            The best way is to use asset() helper. But there is another way to handle this by using url() or secure_url() helper



            <script src="{{ url(mix('css/app.css')) }}"></script>


            or



            <script src="{{ secure_url(mix('css/app.css')) }}"></script>





            share|improve this answer




























              0














              The best way is to use asset() helper. But there is another way to handle this by using url() or secure_url() helper



              <script src="{{ url(mix('css/app.css')) }}"></script>


              or



              <script src="{{ secure_url(mix('css/app.css')) }}"></script>





              share|improve this answer


























                0












                0








                0






                The best way is to use asset() helper. But there is another way to handle this by using url() or secure_url() helper



                <script src="{{ url(mix('css/app.css')) }}"></script>


                or



                <script src="{{ secure_url(mix('css/app.css')) }}"></script>





                share|improve this answer














                The best way is to use asset() helper. But there is another way to handle this by using url() or secure_url() helper



                <script src="{{ url(mix('css/app.css')) }}"></script>


                or



                <script src="{{ secure_url(mix('css/app.css')) }}"></script>






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 20 at 21:27

























                answered Nov 20 at 9:57









                shahabphp

                1115




                1115






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43815086%2flaravel-mix-generates-relative-paths%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Wiesbaden

                    Marschland

                    Dieringhausen