Reputation: 188
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
[name]
is this largeUpvotes: 1
Views: 619
Reputation: 10897
Yes, you can change [name].[chunkhash]
to [contenthash:5]
to reduce bundle file names and keeping long term cache.
Upvotes: 2