Laravel-mix: Problem with Laravel Mix when using async vue component

Created on 8 Jun 2020  路  8Comments  路  Source: JeffreyWay/laravel-mix

Description:

Laravel-Mix version : 5

My webpack.mix.js file:

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


mix.js('resources/assets/js/app.js', 'assets/js')
    .sass('resources/assets/sass/app.scss', 'assets/css')
    .sass('resources/assets/sass/vendor.scss', 'assets/css')
    .copy('resources/assets/images', 'assets/images')
    .options({
        processCssUrls: false,
        postCss: [tailwindcss('./tailwind.config.js')],
    })
    .extract()
    .purgeCss()
    .browserSync('http://localhost:8080');

I created some Vue component and tried to include them as async:

import Vue from 'vue'
import App from './App.vue'
import Router from 'vue-router'

const Dashboard = () => import(/* webpackChunkName: "./assets/js/dashboard" */ './components/Dashboard')
const DashboardHome = () => import(/* webpackChunkName: "./assets/js/dashboard" */ './pages/Home')

import store from './store'


Vue.config.productionTip = false

Vue.use(Router)

const routes = [
  { path: '/', redirect: { name: 'DashboardHome' } },
  { path: '/dashboard', component: Dashboard, children: [
      { path: '/', redirect: { name: 'DashboardHome' } },
      { path: 'home', name: 'DashboardHome', component: DashboardHome }
    ]
  }
]

const router = new Router({
  mode: 'hash',
  routes
})

new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app')

The files (js/css) are created but css files contains JS Code when running yarn run prod

https://www.dropbox.com/s/osakt96rgl83sx0/Screenshot%202020-06-08%2022.28.51.png?dl=0

https://www.dropbox.com/s/iw744tfq30xt1v2/Screenshot%202020-06-08%2022.29.19.png?dl=0

How can I fix this issue?

All 8 comments

This is not gonna work the way you expect it to, there is a bug with the extract-text plugin which webpack uses under the hood. Apparently it should be resolved in Webpack 5, however I haven't been able to make it work myself with the alpha branch of mix :/

Ah okay! Thanks @Reached After removing .extract() it worked

So wait till Webpack 5 to fix it

@itsursujit have you been able to resolve this entirely then? Even when removing the extract(), I run into similar issues.

@denjaland Yes after removing the extract(), it's working fine for me

Sigh - mine still throws errors - could you perhaps have a look at https://github.com/JeffreyWay/laravel-mix/issues/2421? Maybe you see something I do wrong in my setup that I just keep overlooking?

For now I'm still not splitting my codebase into chunks, but it's becoming more and more of an issue as our codebase grows ;-)

All seems fine to me.

my code now is:

const mix = require('laravel-mix');
require('laravel-mix-purgecss');
const tailwindcss = require('tailwindcss');
// ...
mix.js('resources/assets/js/app.js', 'assets/js')
    .sass('resources/assets/sass/app.scss', 'assets/css')
    .sass('resources/assets/sass/vendor.scss', 'assets/css')
    .copy('resources/assets/images', 'assets/images')
    .options({
        processCssUrls: false,
        postCss: [tailwindcss('./tailwind.config.js')],
    })
    .purgeCss()
    .browserSync('http://localhost:8080');

@itsursujit thanks for your feedback - much appreciated - I'll dig into it again a bit later again.

All seems fine to me.

my code now is:

const mix = require('laravel-mix');
require('laravel-mix-purgecss');
const tailwindcss = require('tailwindcss');
// ...
mix.js('resources/assets/js/app.js', 'assets/js')
    .sass('resources/assets/sass/app.scss', 'assets/css')
    .sass('resources/assets/sass/vendor.scss', 'assets/css')
    .copy('resources/assets/images', 'assets/images')
    .options({
        processCssUrls: false,
        postCss: [tailwindcss('./tailwind.config.js')],
    })
    .purgeCss()
    .browserSync('http://localhost:8080');

Could you post here your package.json with the respective version of your packages? I'm having the same problem and removing extract didnt solve.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pixieaka picture pixieaka  路  3Comments

Cheddam picture Cheddam  路  3Comments

Bomavi picture Bomavi  路  3Comments

kpilard picture kpilard  路  3Comments

terion-name picture terion-name  路  3Comments