Building tailwind css as public site and vuetify as admin dashboard

547 views Asked by At

I'm trying to build a site with tailwind css and vuetify with separate javascript with app.js for the main site and admin.js for the admin dashboard to reduce size. I'm using laravel-mix with code splitting. Here's my current configuration:

const mix = require('laravel-mix');
const path = require('path');
require('vuetifyjs-mix-extension')

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel applications. By default, we are compiling the CSS
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css', [
        require('postcss-import'),
        require('tailwindcss'),
    ])
    .babelConfig({
        plugins: ['@babel/plugin-syntax-dynamic-import'],
    })
    .webpackConfig({
        output: {
            chunkFilename: 'js/[name].js',
        },
        resolve: {
            alias: {
                ziggy: path.resolve('vendor/tightenco/ziggy/src/js/route.js'),
            },
        },
    });

mix.js('resources/js/admin.js', 'public/js')
    .vuetify('vuetify-loader');

if(mix.inProduction()) {
    mix.version()
        .webpackConfig({
            output: {
                chunkFilename: 'js/[name].js?id=[chunkhash]',
            }
        });
} else {
    mix.sourceMaps();
}

The problem with this config is the compiled app.css is empty for some reason:

 DONE  Compiled successfully in 43435ms                                                                           10:29:10 AM

       Asset      Size              Chunks             Chunk Names
/css/app.css   0 bytes  /js/admin, /js/app  [emitted]  /js/admin, /js/app
/js/admin.js  6.52 MiB           /js/admin  [emitted]  /js/admin
  /js/app.js  3.28 MiB             /js/app  [emitted]  /js/app
     js/0.js  61.1 KiB                   0  [emitted]  
     js/1.js  76.1 KiB                   1  [emitted]  
    js/10.js   346 KiB                  10  [emitted]  
    js/11.js   283 KiB                  11  [emitted]  
    js/12.js  64.9 KiB                  12  [emitted]  
    js/13.js  82.9 KiB                  13  [emitted]  
    js/14.js  65.5 KiB                  14  [emitted]  
    js/15.js  94.3 KiB                  15  [emitted]  
    js/16.js  78.2 KiB                  16  [emitted]  
    js/17.js  53.2 KiB                  17  [emitted]  
    js/18.js  32.8 KiB                  18  [emitted]  
    js/19.js  15.8 KiB                  19  [emitted]  
     js/2.js   202 KiB                   2  [emitted]  
    js/20.js  15.2 KiB                  20  [emitted]  
    js/21.js  17.8 KiB                  21  [emitted]  
    js/22.js  35.3 KiB                  22  [emitted]  
    js/23.js  40.8 KiB                  23  [emitted]  
    js/24.js   140 KiB                  24  [emitted]  
     js/3.js  74.2 KiB                   3  [emitted]  
     js/4.js  2.01 MiB                   4  [emitted]  
     js/5.js  48.6 KiB                   5  [emitted]  
     js/6.js   118 KiB                   6  [emitted]  
     js/7.js  80.1 KiB                   7  [emitted]  
     js/8.js  55.5 KiB                   8  [emitted]  
     js/9.js  42.2 KiB                   9  [emitted]
1

There are 1 answers

0
Daffa Mumtaz On

I managed to solve the problem based on this github issue. I just need to add entry to my css file in webpack config, like this:

.webpackConfig({
    entry: {
        main: ['./resources/css/app.css']
    },
    output: {
        chunkFilename: 'js/[name].js',
    },
    resolve: {
        alias: {
            ziggy: path.resolve('vendor/tightenco/ziggy/src/js/route.js'),
        },
    },
});