I'm working on a Laravel + Vue SPA project and I tried to optimize the project with code splitting and defining lazy routes, but now every lazy route file are not being versioned.
Let's see if I can describe the problem.
You can see here the main files are versioned: app.css, app.js, vendors.js.
But what happens with users.js? It's a lazy route.
app.blade.php
<!doctype html>
<html lang="ca_ES">
<head>
<link rel="manifest" href="/fullscreen-manifest.json">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<link rel="shortcut icon" href="{{ asset('favicon.png') }}">
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href='https://fonts.googleapis.com/css?family=Roboto:100,300,500,700,900|Material+Icons' rel="stylesheet">
<link href="{{ mix('css/app.css') }}" rel="stylesheet">
</head>
<body>
<div id="app"></div>
<script src="{{ mix('js/app.js') }}" defer></script>
<script src="{{ mix('vendors.js') }}" defer></script>
</body>
</html>
routes.js
const home = () => import(/* webpackChunkName: "home" */ '@/pages/home');
const login = () => import(/* webpackChunkName: "home" */ '@/pages/auth/login');
const pageNotFound = () => import(/* webpackChunkName: "home" */ '@/pages/errors/404');
const pageForbidden = () => import(/* webpackChunkName: "home" */ '@/pages/errors/403');
import users from "./users";
import profile from "./profile";
(...)
export default [
...users,
...profile,
(...)
{
path: '/',
name: 'home',
component: home,
meta: {
auth: true,
}
},
{
path: '/forbidden',
name: '403',
component: pageForbidden,
meta: {
auth: true,
}
},
{
path: '/login',
name: 'login',
component: login,
meta: {
guest: true,
}
},
{
path: '*',
name: '404',
component: pageNotFound,
}
];
users.js
const users = () => import(/* webpackChunkName: "users" */ '@/pages/users/index');
const show = () => import(/* webpackChunkName: "users" */ '@/pages/users/show');
export default [
{
path: '/users',
name: 'users',
component: users,
meta: {
auth: true,
admin: true,
}
},
{
path: '/show/:id',
name: 'users.show',
component: show,
meta: {
auth: true,
admin: true,
}
},
];
webpack.config.js
const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CompressionPlugin = require('compression-webpack-plugin');
const moment = require('moment');
module.exports = {
output: {
chunkFilename: '[name].js',
},
resolve: {
extensions: ['.js', '.json', '.vue'],
alias: {
'@': path.join(__dirname, './resources/js'),
}
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
reportFilename: 'bundle-analyzer-plugin/reports/' + moment().format('YYYYMMDD') + '.html'
}),
new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.7
}),
],
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
};
webpack.mix.js
const config = require('./webpack.config');
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.sass('resources/sass/pdf.scss', 'public/css');
if (mix.inProduction()) {
mix.version();
}
mix.webpackConfig(config);
So what am I doing wrong? I can import all lazy routes files on the app.blade.php and it would be importing with versioning, but I will be missing the point... The idea is this files are being include when the websites need them. But when they do that automatically it does without versioning.

route.jsor router filechunkFilenamelikechunkFilename: '[name].js?t=' + new Date().getTime()?app.blade.phpI cannot import vendors.js.Unable to locate Mix file: /vendors.js. (View: /var/www/html/resources/views/app.blade.php). And I think it's unappropiated adding the time suffix on importing the file.