-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathwebpack.config.js
More file actions
123 lines (121 loc) · 4.1 KB
/
Copy pathwebpack.config.js
File metadata and controls
123 lines (121 loc) · 4.1 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*global
__DEV__
__dirname
process
*/
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: [
'babel-polyfill',
path.join(__dirname, 'app/index.jsx'),
],
output: {
path: path.join(__dirname, 'dev'),
filename: 'bundle.js'
},
resolve: {
extensions: ['.js', '.jsx', '.scss', '.css'],
alias: {
components: path.join(__dirname, 'app/components/'),
containers: path.join(__dirname, 'app/containers/'),
constants: path.join(__dirname, 'app/constants/'),
actions: path.join(__dirname, 'app/actions/'),
reducers: path.join(__dirname, 'app/reducers/'),
util: path.join(__dirname, 'app/util/'),
fetch: path.join(__dirname, 'app/fetch/'),
config: path.join(__dirname, 'app/config/'),
static: path.join(__dirname, 'app/static/')
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
'react-hot-loader',
'babel-loader'
]
},
{
test: /\.(jpg|jpeg|png|svg|gif|bmp)/i,
use: [
'url-loader?limit=5000'
]
},
{
test: /\.(png|woff|woff2|svg|ttf|eot)($|\?)/i,
use: [
'url-loader?limit=5000'
]
},
{
test: /\.(css|scss)$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
//resolve-url-loader may be chained before sass-loader if necessary
use: [
{
loader: "css-loader",
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
{
loader: "sass-loader",
options: {
sourceMap: true
}
}
]
})
}
]
},
plugins: [
// Scope hosting
new webpack.optimize.ModuleConcatenationPlugin(),
new ExtractTextPlugin({
filename: 'main.css',
disable: true
}),
// html 模板插件
new HtmlWebpackPlugin({
template: __dirname + '/app/index.html'
}),
// 热加载插件
new webpack.HotModuleReplacementPlugin(),
// 可在业务 js 代码中使用 __DEV__ 判断是否是dev模式(dev模式下可以提示错误、测试报告等, production模式不提示)
new webpack.DefinePlugin({
__DEV__: JSON.stringify(JSON.parse((process.env.NODE_ENV == 'dev') || 'false'))
})
],
devServer: {
proxy: {
// 凡是 `/api` 开头的 http 请求,都会被代理到 localhost:7777 上,由 koa 提供 mock 数据。
// koa 代码在 ./mock 目录中,启动命令为 npm run mock
'/api': {
target: 'http://localhost:7777',
secure: false
}
},
host: '0.0.0.0',
port: '9999',
disableHostCheck: true, // 为了手机可以访问
contentBase: './dev', // 本地服务器所加载的页面所在的目录
historyApiFallback: true, // 为了SPA应用服务
inline: true, //实时刷新
hot: true // 使用热加载插件 HotModuleReplacementPlugin
}
}