Компоненты отложенной загрузки не работают с Vue Router - PullRequest
1 голос
/ 13 мая 2019

При попытке ленивой загрузки компонентов в моем файле rout.js мой CSS не компилируется.

При использовании оператора импорта в верхней части файла все работает как положено. Нет ошибок консоли или ошибок компиляции. Я использую Vue.js, Vue-Router, Laravel и Laravel-Mix (все последние версии)

//Working (CSS is present)
import Home from '../../components/admin/Home';

//Not Working (No CSS is present)
function loadView(view) {
    return () => import(/* webpackChunkName: "view-[request]" */ `../../components/admin/${view}.vue`)
}

//How I'm initializing the component
let routes = [
    { 
        path: '/', 
        name: 'home',
        component: loadView('Home'),
        meta: { 
            requiresAuth: true
        }
    }]

//Laravel Mix Config
const mix = require('laravel-mix');
const webpack = require('webpack');

mix.js('resources/js/apps/registration/app.js', 'public/js/apps/registration/app.js')
   .js('resources/js/apps/admin/app.js', 'public/js/apps/admin/app.js')
   .js('resources/js/material-dashboard.js', 'public/js/material-dashboard.js')
   .js('resources/js/material-dashboard-extras.js', 'public/js/material-dashboard-extras.js')
   .sass('resources/sass/app.scss', 'public/css');

 mix.webpackConfig({
   plugins: [
      /**
       * Bug with moment.js library causing ./locale not to be found
       * https://github.com/moment/moment/issues/2979
       * Created an empty module running npm install --save empty-module and then doing the below
       */
      new webpack.ContextReplacementPlugin(/\.\/locale$/, 'empty-module', false, /js$/),
      /**
       * Global objects are not getting recognized via require
       * Set them up here
       * global_name: path or module
       */
      new webpack.ProvidePlugin({
         /**
          * There was an error with Popper not being defined due to Popper being included in Bootstrap
          * https://github.com/FezVrasta/bootstrap-material-design/issues/1296
          */
         'Popper': 'popper.js/dist/umd/popper'
     })
  ]
 });

Приложены скриншоты того, что я имею в виду, что CSS не применяется

Как выглядит страница с импортом

Как выглядит страница при ленивой загрузке компонентов в rout.js

1 Ответ

1 голос
/ 13 мая 2019

Вы не должны импортировать имя чанка веб-пакета, вместо этого просто указывайте путь к компоненту примерно так:

//Not Working (No CSS is present)
function loadView(view) {
    return () => import(  `../../components/admin/${view}.vue`)
}

Примечание: не проверено, надеюсь, это поможет:)

...