コマンドでビルドを実行すると、この問題が発生しますnpm run build
。
ERROR in ./src/app.jsx
Module parse failed: /Users/antongoncharov/apps/react-js-app/src/app.jsx Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import React, React from 'react';
| import ReactDom from 'react-dom';
| require('./app.scss');
@ multi main
webpack.config.js
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: [
'webpack-dev-server/client?http://0.0.0.0:3000',
'webpack/hot/only-dev-server',
'./src/app'
],
output: {
path: path.resolve('./dist'),
filename: "[name].js"
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loaders: ['react-hot','jsx?insertPragma=React.DOM&harmony','react', 'babel'],
include: path.join('./src/app.jsx', 'src')
}, {
test: /\.scss$/,
loader: ["style", "css", "sass"]
}]
},
resolve: {
modulesDirectories: ['node_modules'],
extensions: ['', '.js','.jsx']
}
};
そして app.jsx
import React, React from 'react';
import ReactDom from 'react-dom';
require('./app.scss');
export default class HelloWorld extends React.Component {
render() {
return <p>Hello, blablabla!</p>;
}
}
ReactDom.render(<HelloWorld />,document.getElementById('main'));
私は何を間違えましたか?先に進まない2日目です。SCSS、jsx、react-hot-loader を使おうとしていますが、うまくいきません。