我正在尝试将我的应用程序转换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" ] }
添加回答
举报
0/150
提交
取消