SPQRInc
SPQRInc

Reputation: 188

Extremely large filenames on chunking

I am using webpack/laravel-mix to bundle my JS-components.

webpack.mix.js

const {EnvironmentPlugin} = require ('webpack');
const mix = require ('laravel-mix');
const glob = require ('glob');
const path = require ('path');
const {CleanWebpackPlugin} = require ('clean-webpack-plugin');
const ChunkRenamePlugin = require ('webpack-chunk-rename-plugin');

require ('laravel-mix-tailwind');
require('laravel-mix-brotli');

mix.webpackConfig ({
    output: {
        chunkFilename: 'js/chunks/[name].[chunkhash].js'
    },
    plugins: [
        new CleanWebpackPlugin ({
            cleanOnceBeforeBuildPatterns: ['js/chunks/**/*']
        }),
        new EnvironmentPlugin ({
            BASE_URL: '/'
        }),
        new ChunkRenamePlugin ({
            initialChunksWithEntry: true,
            '/js/app': 'js/entry-point.js',
            '/js/vendor': 'js/vendor.js',
        }),
    ],
    module: {
        rules: [
            {
                test: /node_modules(?:\/|\\).+\.js$/,
                loader: 'babel-loader',
                options: {
                    presets: [['@babel/preset-env', {targets: 'last 2 versions, ie >= 10'}]],
                    plugins: ['@babel/plugin-transform-destructuring', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-transform-template-literals'],
                    babelrc: false
                }
            },
            {
                enforce: 'pre',
                test: /\.(js|vue)$/,
                loader: 'eslint-loader',
                exclude: /node_modules/
            }
        ]
    },
    resolve: {
        alias: {
            '@': path.join (__dirname, 'resources'),
            'node_modules': path.join (__dirname, 'node_modules')
        }
    },
});

mix.js ('resources/js/entry-point.js', 'public/js')
.postCss ('resources/css/app.css', 'public/css')
.tailwind ('./tailwind.config.js')
.brotli();

if (mix.inProduction ()) {
    mix
    .version ();
}

This works fine. But there is one thing that bothers me:

If I reuse Vue-components like dropdown-buttons in multiple views, the filename looks like this:

Component, that is used on

Is returning this file name:

js/chunks/foo-edit~foo-index~field-edit~field-index~field-view~bar-edit~bar-index~bar-view~pro~07fab756.61fe59df34cc4cf440ce.js

My questions:

  1. What is causing this effect? I tried to understand the docs but don't get the reason why [name] is this large
  2. How can I prevent this behavior and force short chunk names on shared components?

Upvotes: 1

Views: 619

Answers (1)

Masih Jahangiri
Masih Jahangiri

Reputation: 10897

Yes, you can change [name].[chunkhash] to [contenthash:5] to reduce bundle file names and keeping long term cache.

Upvotes: 2

Related Questions