Answer the question
In order to leave comments, you need to log in
How to setup html-webpack-plugin in laravel?
The task is to add a hash to the files when building.
webpack config:
export default {
entry: {
app: './react/src/app/index',
},
output: {
path: __dirname + '/public',
publicPath: '/',
filename: 'assets/js/[name].[contenthash].bundle.js'
},
plugins: [
new HTMLWebpackPlugin({
template: './react/src/app/index.html'
})
]
};
public
necessary html is generated in my folder and the actual path to the file is substituted into it<script src="/assets/js/app.e038cfa2f592a3f951d8.bundle.js"></script>
index.html
from the public
. The content is taken from resources/views/index.blade.php
where the path to the file is coded<script defer src="{{ asset('assets/js/app.bundle.js') }}"></script>
laravel-mix
, I'm smoking its documentation...
Answer the question
In order to leave comments, you need to log in
The problem was eventually solved by means of the framework through Laravel-mix
I won’t suggest a universal solution, but you have html-webpack-lugin , you can probably just rename your index.html to a .php file, insert the necessary code, and specify the path where to save it in the laravel project in additional parameters. For example in layoyts. The plugin itself will substitute the script and style files, the rest will not be touched.
new HTMLWebpackPlugin({
template: './react/src/app/index.html'
})
In order not to bother with such a problem, I did the following: I added a certain hash inside the asset connection. Those. wrote like this:
<script defer src="{{ asset('assets/js/app.bundle.js') . "?" . md5(time()) }}"></script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question