papagray's avatar

Laravel Vue Production Setup

I have a laravel vue project that works fine in development. I have been trying to get it unto our production server for some hours now. However when I visit the URL, I get a blank page. Upon inspection in the console, I notice all the js chunk files return status of 200 but their contents are "We're sorry but Project Name doesn't work properly without Javascript".

Here is a snippet of my webpack.mix.js:

mix
  .js('resources/js/app.js', 'public/js')
  .webpackConfig({
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'frontend/src/'),
        '@themeConfig': path.resolve(__dirname, 'frontend/themeConfig.js'),
        '@core': path.resolve(__dirname, 'frontend/src/@core'),
        '@validations': path.resolve(__dirname, 'frontend/src/@core/utils/validations/validations.js'),
        '@axios': path.resolve(__dirname, 'frontend/src/libs/axios')
      }
    },
    module: {
      rules: [
        {
          test: /\.s[ac]ss$/i,
          use: [
            {
              loader: 'sass-loader',
              options: {
                sassOptions: {
                  includePaths: ['frontend/node_modules', 'frontend/src/assets']
                }
              }
            }
          ]
        },
        {
          test: /(\.(png|jpe?g|gif|webp)$|^((?!font).)*\.svg$)/,
          loaders: {
            loader: 'file-loader',
            options: {
              name: 'images/[path][name].[ext]',
              context: '../vuexy-vuejs-bootstrap-vue-template/src/assets/images'
              //   context: 'frontend/src/assets/images'
            }
          }
        }
      ]
    }
  })
  .sass('resources/sass/app.scss', 'public/css')
  .options({
    postCss: [require('autoprefixer'), require('postcss-rtl')]
  })

// ------------------------------------------------
// If you are deploying on subdomain/subfolder. Uncomment below code before running 'yarn prod' or 'npm run production' command.
// Please Change below 'publicPath' and 'setResourceRoot' options as per your sub-directory path. 
// ------------------------------------------------


 if (mix.inProduction()) {
   mix.version()
   mix.webpackConfig({
     output: {
       publicPath: '/app/',
       chunkFilename: 'js/chunks/[name].[chunkhash].js'
     }
   })
   mix.setResourceRoot('/app/')
 }else{ 
    mix.webpackConfig({
        output: {
            chunkFilename: 'js/chunks/[name].js'
        } 
    })
}

I setup production using:

npm run prod

Then I run this on the server via ssh

composer install --optimize-autoloader --no-dev

php	artisan key:generate

In the console, the js chunk files show this as their response from the server:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="csrf-token" content="j9kLqaAInZ4043rRqT9Zn3kNMHaSfCdF7h5ejnnZ">
<link rel="icon" href="/favicon.ico">
<title>project Title</title>

<link rel="stylesheet" href="https://app.myprojects.com/css/app.css?id=bff15ac59733e85aedce">

<link rel="shortcut icon" href="https://app.myprojects.com/images/logo/favicon.png">
</head>
<body>
<noscript>
    <strong>We're sorry but this platform doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
  </noscript>
<div id="app">
</div>
<script src="https://app.myprojects.com/js/app.js?id=a74eb61fbd09ea2e1e92"></script>
</body>
</html>

Please help

0 likes
1 reply

Please or to participate in this conversation.