I'm just getting started working with webpack, but I'm stumped at a rather simple problem.
To try to solve it, I've been looking around the web, but for some reason I can't find examples using vanilla javascript function methods with webpack. I have no problem exporting, importing, and executing imported functions.
The problem is I can't execute imported function methods, and I don't understand why. The functions are imported correctly, and can be executed. The methods cannot be executed.
In this case, I can execute model(), but when I try to call model.alertone(), I get the error "model.alertone is not a function".
Here is the code:
model.js:
function model() {
var alertone = () => {alert("This works")};
return {
alertone
}
};
export default model;
index.js:
import model from "./model.js";
model();
model.alertone();
Webpack configuration:
const path = require('path');
module.exports = {
mode: "development",
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
}
};