How can I connect js to html using webpack?

There is a code for example:
the <body>
 <h1>Hello There</h1>
 <h2>General Kenobi</h2>
 <script src="dist/main.js"></script>




When it is evaluated by writing -

so <script src="dist/main.js"></script> be doing wrong. All necessary files must be created using webpack




Tell me how to connect the js file to html using webpack?


My webpack config if:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
 entry: {
 app: './src/screens/app/index.js',
 landing: './src/screens/landing/index.js'
},
 mode: 'development',
 output: {
 path: path.resolve(__dirname, 'dist'),
 filename: "[name]/main.js"
},
 module: {
 rules: [
{
 test: /\.js$/,
 enforce: 'pre',
 exclude: /node_modules/,
 loader: 'eslint-loader',
},
{
 test: /\.scss$/,
 use: [{
 loader: "style-loader"
 }, {
 loader: "css-loader"
 }, {
 loader: "sass-loader",
}]
},
{
 test: /\.(jpg|png|svg|ttf|woff|eot)$/,
 loader: 'url-loader',
 options: {
 name: 'img/[name].[ext]',
},
}
],
},
 plugins: [
 new HtmlWebpackPlugin({
 inject: true
 chunks: ['app'],
 template: 'src/screens/app/app.html',
 filename: 'app/app.html'
}),
 new HtmlWebpackPlugin({
 inject: true
 chunks: ['landing'],
 template: 'src/screens/landing/landing.html',
 filename: 'landing/landing.html'
})
]
};
April 4th 20 at 00:55
0 answer

Find more questions by tags JavaScriptHTMLWebpack