-
Notifications
You must be signed in to change notification settings - Fork 48
/
webpack.config.js
83 lines (82 loc) · 2.18 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
77
78
79
80
81
82
83
var webpack = require("webpack");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var path = require("path");
var port = 3010;
var demoNum = 3;
module.exports = {
context: path.resolve(__dirname, "example"), // string(绝对路径!)
devtool: "eval",
cache: true,
entry: [
"react-hot-loader/patch",
// 开启 React 代码的模块热替换(HMR)
"webpack-dev-server/client?http://0.0.0.0:" + port,
"webpack/hot/only-dev-server",
"./App"+demoNum+".jsx"
],
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
// 当模块热替换(HMR)时在浏览器控制台输出对用户更友好的模块名字信息
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: true
}
}),
new HtmlWebpackPlugin({
title: "Custom template",
template: "./index"+demoNum+".html", // Load a custom template (ejs by default see the FAQ for details)
hash: true,
filename: "./index.html"
})
],
resolve: {
modules: ["node_modules", path.resolve(__dirname, "src")],
extensions: [".js", ".jsx"]
},
devServer: {
hot: true,
// 开启服务器的模块热替换(HMR)
host: "0.0.0.0",
port: port
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: "babel-loader",
exclude: /node_modules/,
include: __dirname,
options: {
presets: [["es2015", { modules: false }], "stage-1", "react"],
plugins: [
"react-hot-loader/babel"
// 开启 React 代码的模块热替换(HMR)
]
}
},
{
test: /\.css$/,
use: [
"style-loader",
"css-loader",
{ loader: "postcss-loader", options: { config: { path: "./postcss.config.js" } } }
]
},
{
test: /\.less/,
use: [
"style-loader",
"css-loader",
{ loader: "postcss-loader", options: { config: { path: "./postcss.config.js" } } },
"less-loader"
]
},
{
test: /\.(gif|jpg|png|woff|svg|eot|ttf)$/,
use: [{ loader: "file-loader" }]
}
]
}
};