问题
How can I webpack
a web app into an output .html
file, starting from a traditional input .html
?
Here is a simple starting point:
index.html
<body>
<output></output>
<script src="./main.js"></script>
</body>
main.js
import React from "react";
document.querySelector("output").innerText = React.version;
webpack.config.js
module.exports = {
entry: "./index.html",
output: {
filename: "output.html"
},
module: {
rules: [
{test: /^index\.html$/, use: [
{loader: "extract-loader"},
{loader: "html-loader", options: {
attrs: ["script:src"]
}}
]}
]
}
}
This results in SyntaxError: Unexpected token import
when processing main.js
, however.
来源:https://stackoverflow.com/questions/45063362/using-webpack-with-a-html-entry