我是webpack的新手。我正在学习react并使用webpack为其构建环境。
我有一个webpack-config.js文件。
var path = require('path');
module.exports = {
mode: 'production',
entry: './script.js',
output:
{
path: path.resolve(__dirname, 'src'),
filename: 'transpiled.js'
},
module:
{
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query:
{
presets: ['es2015','react']
}
}
]
}
}
和 script.js
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Hello world</h1>
document.getElementByIdName('first')
);
和 index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="first"></div>
<script src="transpiled.js"></script>
</body>
</html>
在 Pakage.json 文件中我已经写了。
"scripts": {
"it": "webpack-dev-server --hot"
},
但是当我使用"npm run it"运行npm时,它向我显示以下错误:
配置警告 'mode'选项未设置。将'mode'选项设置为'development'或'production'以启用此环境的默认值。 多个错误 -dev-derver/client?http://localhost:8080 webpack/hot/dev-server ./src 找不到模块:错误:无法解析'D:\ React Js \ LearnReact'中的'./src' @multi -dev-derver/client?http://localhost:8080 webpack/hot/dev-server ./src i ?wdm?:编译失败。
请帮帮我,我真的卡住了,想知道解决方案。
src
文件夹吗? - brkwebpack.config.js
。请查看文档https://webpack.js.org/configuration/。 - Joshua