为了账号安全,请及时绑定邮箱和手机立即绑定

./index.html 中的语法错误

./index.html 中的语法错误

撒科打诨 2023-04-01 17:17:03
我正在尝试将我的应用程序转换create-react-app为与 Webpack 兼容的应用程序。我不能清楚地理解我做了什么,我经常会出错:ERROR in ./index.htmlModule build failed (from ./node_modules/babel-loader/lib/index.js):SyntaxError: /mnt/c/Users/.../index.html: Unexpected token (1:0)> 1 | <!doctype html>    | ^  2 | <html>  3 |   <head>  4 |     <title>Getting Started</title>    at Object._raise [...]启动后会发生这种情况npm start这是我的配置:结构索引.htmlwebpack.config.js巴贝尔源代码/index.js包.json./index.html<!doctype html><html>  <head>    <title>Getting Started</title>    <script src="https://unpkg.com/lodash@4.16.6"></script>  </head>  <body>    <script src="./src/index.js"></script>  </body></html>./src/index.jsimport React from 'react';import ReactDOM from 'react-dom';import './index.css';import App from './App';import * as serviceWorker from './serviceWorker';ReactDOM.render(  <React.StrictMode>    <App />  </React.StrictMode>,  document.getElementById('root'));serviceWorker.unregister();./webpack.config.jsconst webpack = require('webpack');const path = require('path');const config = {  entry: [    'react-hot-loader/patch',    './index.html'  ],  output: {    path: path.resolve(__dirname, 'dist'),    filename: 'bundle.js'  },  module: {    rules: [        {            test: /\.js$|jsx$|html/,            exclude: /(node_modules|bower_components)/,            loader: 'babel-loader',            query: {                presets: ['@babel/preset-env', '@babel/react']            }        }    ]  },  resolve: {    extensions: [      '.js',      '.jsx',      '.html'    ],    alias: {      'react-dom': '@hot-loader/react-dom'    }  },  devServer: {    contentBase: './dist'  }};module.exports = config;最后,我的./.babelrc  {    "plugins": ["@babel/transform-react-jsx"],    "ignore": [      "foo.js",      "bar/**/*.js"    ]  }
查看完整描述

1 回答

?
largeQ

TA贡献2039条经验 获得超7个赞

您正在为您的 html 使用 javascript 加载程序,这是行不通的。

您应该改用html -loader


查看完整回答
反对 回复 2023-04-01
  • 1 回答
  • 0 关注
  • 110 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信