如何设置正确反应
How to setup react properly
我一直在关注 codecademy 上的 React 设置说明:
当我在终端中输入“npm 运行 build”时,出现此错误:
我似乎不知道如何让它工作。
这是我在 github 上的代码的 link:
https://github.com/throwkill999/react_demo
错误告诉您 output.build
不是一个有效的选项。您可能打算为此使用 output.path
. There are other problems with how you concatenate __dirname
in some places, because you need a leading /
for them. But it's better to use path.resolve
。
您的配置如下所示:
var path = require('path');
var HTMLWebpackPlugin = require('html-webpack-plugin');
var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
template: path.resolve(__dirname, 'app/index.html'),
filename: 'index.html',
inject: 'body'
});
module.exports = {
entry: path.resolve(__dirname, 'app/index.js'),
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
},
output: {
filename: 'transformed.js',
path: path.resolve(__dirname, 'build')
},
plugins: [HTMLWebpackPluginConfig]
};
还有./app/index.js
你打错了,应该是./components/Apps
(你忘记了s
)。
我一直在关注 codecademy 上的 React 设置说明:
当我在终端中输入“npm 运行 build”时,出现此错误:
我似乎不知道如何让它工作。
这是我在 github 上的代码的 link: https://github.com/throwkill999/react_demo
错误告诉您 output.build
不是一个有效的选项。您可能打算为此使用 output.path
. There are other problems with how you concatenate __dirname
in some places, because you need a leading /
for them. But it's better to use path.resolve
。
您的配置如下所示:
var path = require('path');
var HTMLWebpackPlugin = require('html-webpack-plugin');
var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
template: path.resolve(__dirname, 'app/index.html'),
filename: 'index.html',
inject: 'body'
});
module.exports = {
entry: path.resolve(__dirname, 'app/index.js'),
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
},
output: {
filename: 'transformed.js',
path: path.resolve(__dirname, 'build')
},
plugins: [HTMLWebpackPluginConfig]
};
还有./app/index.js
你打错了,应该是./components/Apps
(你忘记了s
)。