Khi tôi viết webpack.config.js như thế này
module.exports = {
entry: './index.jsx',
output: {
filename: 'bundle.js'
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}]
}
};
Và trong index.jsxtôi nhập một reactmô-đunApp
import React from 'react';
import { render } from 'react-dom';
import App from './containers/App';
let rootElement = document.getElementById('box')
render(
<App />,
rootElement
)
Tôi thấy nếu tôi đặt tên ứng dụng mô-đun trong App.jsx, thì webpack sẽ thông báo trong index.jsxkhông thể tìm thấy mô-đun App, nhưng nếu tôi đặt tên ứng dụng mô-đun đã đặt tên trong App.js, nó sẽ tìm thấy mô-đun này và hoạt động tốt.
Vì vậy, tôi nhầm lẫn về nó. Trong của tôi webpack.config.js, tôi đã viết test: /\.jsx?$/để kiểm tra tệp, nhưng tại sao *.jsxkhông tìm thấy tên?

rules đã được liệt kê dướimodule...{ module: { rules: [ { test: /\.jsx?$/, resolve: { extensions: [".js", ".jsx"] }, include: ... } ] }