-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
76 lines (73 loc) · 1.75 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const webpack = require("webpack");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: [
"react-hot-loader/patch",
// 'webpack-dev-server/client?http://localhost:8080',
// 为 webpack-dev-server 的环境打包代码
// 然后连接到指定服务器域名与端口
// "webpack/hot/only-dev-server",
// 为热替换(HMR)打包好代码
// only- 意味着只有成功更新运行代码才会执行热替换(HMR)
"./example/index.js"
],
output: {
filename: "bundle.js",
path: __dirname + "/dist"
},
devtool: "inline-source-map",
resolve: {
extensions: [".js"]
// alias: {
// utils: path.resolve(__dirname, 'src/utils'),
// apis: path.resolve(__dirname, 'src/apis'),
// }
},
module: {
rules: [
{
test: /\.jsx?$/,
use: ["babel-loader"],
exclude: /node_modules/
},
{
enforce: "pre",
test: "/.js$/",
loader: "source-map-loader"
},
{
test: /\.less$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader"
},
{
loader: "less-loader"
}
]
}
]
},
devServer: {
port: 8090,
host: "localhost",
contentBase: path.resolve(__dirname, "dist"),
// 输出文件的路径
publicPath: "/",
// 和上文 output 的“publicPath”值保持一致
hot: true
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
title: "Example",
chunksSortMode: "dependency",
template: path.resolve(__dirname, "./example/index.ejs")
})
]
};