skoobi's avatar
Level 13

Vite and Webpack

Hi. Im not sure im understanding Vite too well. I have a project that I created they have cPanel hosting with no access to the Terminal (yey!), but if I want to go and push to production, If im right in saying this, I need to run npm from the terminal to run Vite? Is this correct? or am i missing something completely. With webpack or how it used to be it just compiled and that was it, but tried to revert to webpack and Mix, but when running npm run prod it basically only creates an app.css with the @tailwind base;@tailwind components;@tailwind utilities;.

I'm a little confused with it! Any good resources on how to run in production on cPanel with limitied access. Most of the apps I build the customer normally lets me deal with the server side, but these 2 have been a nightmare, including uploading files without git!!! Cheers

0 likes
2 replies
LaryAI's avatar
Level 58

It sounds like you're trying to understand how to build your Vite project for production and deploy it to a cPanel hosting environment where you don't have terminal access. Here's a step-by-step guide to help you through the process:

  1. Build Your Project Locally: First, you need to build your project on your local machine. Vite, like Webpack, has a build command that compiles your project into static assets ready for production. Run the following command in your project directory:

    npm run build
    

    This command will generate a dist directory (or another directory if configured differently in your vite.config.js) with all your compiled assets.

  2. Prepare Your Assets: After running the build command, you should have all your assets ready. These will typically include your JavaScript bundles, CSS files, and any static assets like images or fonts.

  3. Upload to cPanel: Since you don't have terminal access on your cPanel hosting, you'll need to manually upload your files. You can do this using the cPanel's File Manager or an FTP client like FileZilla.

    • Log in to your cPanel account and open the File Manager.
    • Navigate to the public directory where your website is hosted (often public_html).
    • Upload the contents of your local dist directory to the appropriate location on your cPanel hosting.
  4. Update File Paths (if necessary): If your Vite project is configured to use absolute paths, you may need to adjust these to relative paths or configure the base path in your vite.config.js file before building for production. This ensures that the asset paths are correct when deployed on the server.

  5. Test Your Deployment: After uploading the files, visit your website to ensure that everything is working as expected. Check for any console errors or missing assets.

Regarding the issue with Laravel Mix and Tailwind CSS, it sounds like the Tailwind directives are not being processed correctly. Make sure you have installed tailwindcss and its dependencies correctly and that you have configured your webpack.mix.js file to use tailwindcss as a PostCSS plugin.

Here's a basic example of how your webpack.mix.js might look:

const mix = require('laravel-mix');
require('mix-tailwindcss');

mix.js('resources/js/app.js', 'public/js')
   .postCss('resources/css/app.css', 'public/css', [
      require('tailwindcss'),
   ])
   .tailwind('./tailwind.config.js');

And ensure your tailwind.config.js is set up correctly.

If you're still having trouble with Laravel Mix and Tailwind CSS, consider checking the official Tailwind documentation or searching for specific issues related to Laravel Mix and Tailwind integration.

Remember, the key to deploying on cPanel without terminal access is to perform all build steps locally and then upload the production-ready files to your hosting environment.

skoobi's avatar
skoobi
OP
Best Answer
Level 13

Fixed. I noticed i was using postCss instead of sass, but didnt include the

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}```

in the postcss.config file

Please or to participate in this conversation.