Using webpack with a .html entry

不问归期 提交于 2020-12-29 09:34:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!