3

Here is my webpack.config.js

module.exports = {
    entry: "./src/index.js",//path relative to this file
    output: {
        filename: "../frontEnd/bundle.js",//path relative to this file
    },
    externals: {
        puppeteer: 'require("puppeteer")',
    },
    mode: 'development'
  }

Here is the file, index.js, where the webpack is ran:

var backendScript = require('../backEnd/backend');
var safeBackendScript = require('../backEnd/safeBackend');

function test(){
    document.getElementById("Fname").value= "John"
    document.getElementById("Lname").value= "Smith"
    document.getElementById("Phone").value= "1234567890"
    document.getElementById("Email").value= "[email protected]"
    document.getElementById("Saddress").value= "123 Main Street"
    document.getElementById("Zip").value= "12345"
    document.getElementById("country").value= "USA"
    document.getElementById("state").value= "NJ"
    document.getElementById("cardtype").value= "AE"
    document.getElementById("Cname").value= "JOHN H SMTIH"
    document.getElementById("Cnumber").value= "1234567890101112"
    document.getElementById("CVV").value= "123"
    document.getElementById("cardmonth").value= "01"
    document.getElementById("cardyear").value= "2035"
    document.getElementById("category").value= "jackets"
    document.getElementById("kword").value= "Supreme Jacket"
    document.getElementById("delay").value= "120"
    document.getElementById("color").value= "C2"
    document.getElementById("size").value= "L"
}

module.exports = {
    test: test
}

And then here is my html with the function ran:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="index.css">
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>
    <script type= "text/javascript" src="./bundle.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <title>Supreme Bot</title>
</head>
<body style="margin: 20px">
   <button onclick="test()"> test </button>
</body>
</html>

then after clicking on the button, it states that test() is undefined... I can't figure it out... Any help is GREATLY appreciated.

1 Answer 1

7

You aren't exporting test() to window.

module.exports = {...} won't automagically get injected into window, but:

  • you can set the output.libraryTarget: 'window' and output.library: 'something' configuration options and get window.something.test() (docs here), or
  • you can manually do window.test = test; at the end of your Webpack entry point instead of exporting things.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.