【发布时间】:2016-05-03 19:48:07
【问题描述】:
我在尝试使用 Babel6 Stage-1 加载我的 React 应用程序时收到“模块解析失败”错误。我们最初运行的是 browserify,但我现在正试图将我们完全移植到 Babel6。
babel.rc 文件
{
"presets": ["stage-1", "react"],
"env": {
"development": {
"presets": ["react-hmre"]
}
}}
webpack 配置
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: [
'eventsource-polyfill', // necessary for hot reloading with IE
'webpack-hot-middleware/client',
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [{
test: /\.jsx?/,
loaders: ['babel'],
include: path.join(__dirname, 'src'),
},
{
test: /\.css$/,
exclude: /node_modules/,
loader: 'style!css'
}]
}
};
我已尝试阅读有关 Babel6 的文档,看来我需要在我的预设中包含 react 以及 Stage-1。
我都完成了,并且安装了 npm:
babel preset stage 1、babel preset react、babel preset react hmre
关于如何再次加载反应的任何想法?
【问题讨论】:
-
首先它是 .babelrc,而不是 babel.rc。还要确保你有 es2015 预设:babeljs.io/docs/plugins/preset-es2015
标签: node.js reactjs babeljs transpiler ecmascript-2016