我正在尝试使用JavaScript es6制作扑克游戏,但即使使用babel,当游戏运行时,也会抛出以下错误:
意外的保留字
{ import Hand from './hand';
我的node_modules中有以下内容:
babel
babel-core
babel-loader
babel-preset-es2015
webpack.config.js:
"use strict";
module.exports = {
context: __dirname,
entry: "./player.js",
output: {
path: "./bundle",
filename: "bundle.js"
},
module: {
loaders: [
{
test: [/\.jsx?$/, /\.js?$/],
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015']
}
}
]
},
devtool: 'source-maps',
resolve: {
extensions: ["", ".js", '.jsx']
}
};
我试图简单地运行player.js来测试构造函数:
import Hand from './hand';
export default class Player {
constructor(name) {
this.name = name;
this.hand = dealHand();
}
dealHand() {
Hand.deal();
}
}
let me = new Player("sam");
console.log(`my name is ${me.name}`)
console.log(me.hand);