我试图用webpack构建项目,但是我收到了错误。我能够早先用gulp构建这个项目,所以所有路径和一切都应该没问题。我从本文档https://github.com/babel/babel-loader安装了所有babel加载器并复制了示例中的代码。
ERROR in ./src/app.jsx
Module parse failed: ..path../src/app.jsx Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import React from 'react';
| import ReactDom from 'react-dom';
@ multi main

我的webpack.config文件:
var webpack = require("webpack");
var path = require("path");
module.exports = {
devtools: 'inline-source-map',
entry: [
'./src/app.jsx'
],
output: {
path: '../app/www/js/',
filename: 'bundle.js'
},
resolve: {
modulesDirectories: [path.join(__dirname, 'node_modules')],
extensions: ['', '.js', '.jsx', '.scss']
},
modules: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
}
},
{
test: /\.scss$/,
exclude: /(node_modules|bower_components)/,
loaders: ["style", "css", "sass"]
}
]
}
};

答案 0 :(得分:1)
应该是vals
,而不是loader: 'babel'
loader: 'babel-loader'
,而不是module
。