我在尝试让应用程序运行时遇到问题。 使用babel进行编译时,似乎' ='我的.js文件中的符号未被识别...并且它返回我"未捕获错误:模块构建失败:SyntaxError"。我不知道如何解决这个问题,它真的开始让我紧张了:)。 这是我的webpack.config.js
const path = require('path');
module.exports = {
entry: ['babel-polyfill', './lib/main.js'],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname)
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
}
}
]
}
};
这是我的main.js
的开头import React from 'react';
import ReactDOM from 'react-dom';
import _ from 'lodash';
const createArray = (size) => Array.from({ length: size }, (_, i) => i);
class Cell extends React.Component {
backgroundColor = () => {
我的index.html
<!doctype html>
<head>
<meta charset="utf-8">
<title>Memory Game</title>
<!-- certainly some style rules here -->
<link rel="stylesheet" href="../style.css"/>
</head>
<body>
<div id="react"> Loading...</div>
<script src="bundle.js"></script>
</body>
</html>
先谢谢,请记住,我是初学者:) 祝你有愉快的夜晚!
答案 0 :(得分:0)
resources/views/errors/500.blade.php
使用适当的模块:
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015'],
plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy']
}
}
]
}