1 year ago

Lazy loading vue components and laravel-mix issue

Posted 1 year ago by Gabotronix

Hi everybody, I'm trying to lazy load vue components in my laravel-vue app since my app.js file is getting very huge, I tried following the following tutorial but I'm getting an unexpected token error:

This is the tutorial I followed:

This is my webpack config file:

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

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

// Override mix internal webpack output configuration
mix.config.webpackConfig.output = {
   chunkFilename: 'js/[name].bundle.js',
   publicPath: '/',

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css');

My package.json file:

    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    "devDependencies": {
        "axios": "^0.18",
        "babel-plugin-dynamic-import-webpack": "^1.1.0",
        "babel-plugin-syntax-dynamic-import": "^6.18.0",
        "babel-preset-env": "^1.7.0",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^2.0",
        "lodash": "^4.17.4",
        "popper.js": "^1.12",
        "vue": "^2.5.7",
        "vue-moment": "^4.0.0",
        "vue2-editor": "^2.6.6",
        "vuex-persist": "^2.0.0"
    "dependencies": {
        "js-cookie": "^2.2.0",
        "vue-slick": "^1.1.15",
        "vue2-datepicker": "^2.6.4",
        "vuex-persistedstate": "^2.5.4"

The .babelrc file I created:

    "plugins": ["syntax-dynamic-import"]

Any idea what I'm doing wrong?

Please sign in or create an account to participate in this conversation.