Итак, я пытаюсь создать html-файл с именем index.html
на основе template.html
, стиль которого основан на style.css
, и функцию handleClick
, объявленную в index.js
. Код ниже работает для стиля, но handleClick
не работает. Это возможно?
Это мой webpack.config.js
const path = require('path')
const HTMLWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: {
'page': './src/index.js'
},
output: {
path: path.join(__dirname, '/dist'),
filename: "[name].js"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
'babel-loader'
]
},
{
test: /\.css$/,
use: [
"style-loader",
"css-loader"
]
}
]
},
plugins: [
new HTMLWebpackPlugin({
filename: 'index.html',
template: './src/template.html'
})
]
}
Это мой index.js
require('./style.css');
function handleClick(){
alert("called from index")
}
Это мой template.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Page's Title</title>
</head>
<body>
<div>This background should be blue</div>
<button onclick="handleClick()"> click me </button>
</body>
</html>
а это мой style.css
div {
background-color:blue;
}