13

如何从传统输入开始webpack将 Web 应用程序转换为输出文件?.html.html

这是一个简单的起点:

索引.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"]
        }}
      ]}
    ]
  }
}

但是,这会导致在SyntaxError: Unexpected token import处理main.js时。

4

0 回答 0