Skip to content

Embed the script into HTML #1831

Open
Open
@andrzejlisek

Description

@andrzejlisek

I am trying to embed the JavaScript files into HTML file.

I have very simple example for test purposes

test.html

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <meta charset="UTF-8"> 
  </head>
  <body>
    <input type="button" value="SomeButton" onclick="testfn()">
    <script src="script.js"></script>
  </body>
</html>

script.js

function testfn()
{
    alert("hello world");
}

I expect, that I provide the HTML file name into Webpack, the webpack will detect the JS file and will generate this output standalone HTML file:

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <meta charset="UTF-8"> 
  </head>
  <body>
    <input type="button" value="SomeButton" onclick="testfn()">
    <script>
function testfn()
{
    alert("hello world");
}
    </script>
  </body>
</html>

How to configure webpack to do this (package.json and webpack.config.js file)? I can not find, how to bundle such simple example.

The input HTML file is not an template. There is working page file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions