Answer the question
In order to leave comments, you need to log in
How to refer to a file in twig template?
Hello everyone, I ran into a problem, there is a webpack project, there is a need to use twig templates. And there is a need to insert the most necessary js / css files into the positions I need on the page, disabling the inject function,
the file names contain dynamic hashes.
new HtmlWebpackPlugin({
hash: false,
template: `/index.html.twig`,
filename: `/index.html.twig`,
inject: false
}),
new MiniCssExtractPlugin({
filename: `css/[name].[contenthash].css`,
}),
new HtmlWebpackPlugin({
hash: false,
template: `/index.html`,
filename: `/index.html`,
inject: false
}),
<link rel="stylesheet" href="<%= htmlWebpackPlugin.files.chunks.base.css %>">
<script async src="<%= htmlWebpackPlugin.files.chunks.vendors.entry %>"></script>
Answer the question
In order to leave comments, you need to log in
I am writing my own solution for the blade templating engine, but there is no need to be afraid, it is the same there, just the designs are different.
webpack.config.js:
new HtmlWebpackPlugin({
template: "resources/js/template_vanilla.ejs",
filename: path.resolve(__dirname, 'resources/views/inline/vanilla.blade.php'),
inject: false,
publicPath: '/assets',
}),
<% let styles = htmlWebpackPlugin.files.css; %>
<% let scripts = htmlWebpackPlugin.files.js; %>
<% for (let style of styles) { %>
<link rel="stylesheet" href="<%= style %>">
<% } %>
<% for (let script of scripts) { %>
<script src="<%= script %>"></script>
<% } %>
<script src="/assets/js.ebb3174236087eacfa7b.bundle.js"></script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question