Search code examples
webpackhtml-webpack-plugin

Files In templateParameters


In HtmlWebpackPlugin configurations when I specify templateParameters I no longer have access to my files in the template.

Webpack Config:

plugins: [
    new HtmlWebpackPlugin({ 
        template: './app/index.ejs', 
        inject: false, 
        templateParameters: configJSON 
    })
],

Template:

<script src="<%= htmlWebpackPlugin.files.js[0] %>"></script>

Is there a way to access files while using templateParameters?


Solution

  • Looked over the source code and found that templateParameters can also be a function and has the parameters compilation, assets, options. The assets parameter has all the files. The object returned from this function will be the templateParameters.