-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.config.js
210 lines (200 loc) · 7.18 KB
/
webpack.dev.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
var path = require("path")
var webpack = require('webpack')
var autoprefixer = require('autoprefixer')
var ExtractTextPlugin = require("extract-text-webpack-plugin")
// html-webpack-plugin插件,webpack中生成HTML的插件,
// 具体可以去这里查看https://www.npmjs.com/package/html-webpack-plugin
var HtmlWebpackPlugin = require('html-webpack-plugin')
var webpackConfig = {
devtool: 'cheap-module-eval-source-map',
devServer: {
historyApiFallback: true,
inline: true,
port: 9090,
//host: '192.168.199.81',
compress: true,
// https://webpack.github.io/docs/node.js-api.html
// https://github.com/webpack/webpack/blob/master/lib/Stats.js#L50
stats: {
chunkModules: false,
modules: false,
error: true,
errorDetails: true,
publicPath: true
},
proxy: {
// 开发环境
'/crm/api/*': {
target: 'http://dev.hbbcare.com:8087/crm/api',
pathRewrite: {
'^/crm/api': ''
},
changeOrigin: true
},
// yfy
// '/crm/api/*': {
// target: 'http://192.168.199.81:8087/crm/api',
// pathRewrite: {
// '^/crm/api': ''
// },
// changeOrigin: true
// },
// 测试环境
// '/crm/api/*': {
// target: 'http://test.hbbcare.com:8088/crm/api',
// pathRewrite: {
// '^/crm/api': ''
// },
// changeOrigin: true
// },
// // 田春阳
// '/crm/api/*': {
// target: 'http://192.168.3.177:8087/crm/api',
// pathRewrite: {
// '^/crm/api': ''
// },
// changeOrigin: true
// },
//王月强
// '/crm/api/*': {
// target: 'http://192.168.199.125:8087/crm/api',
// pathRewrite: {
// '^/crm/api': ''
// },
// changeOrigin: true
// },
// 测试环境
// '/crm/api/*': {
// target: 'http://test.hbbcare.com:8088/crm/api',
// pathRewrite: {
// '^/crm/api': ''
// },
// changeOrigin: true
// },
// 本地
// '/crm/api/*': {
// target: 'http://127.0.0.1:8087/crm/api',
// pathRewrite: {
// '^/crm/api': ''
// },
// changeOrigin: true
// },
}
},
/*
* 指定node_modules目录, 如果项目中存在多个node_modules时,这个很重要.
* import js或者jsx文件时,可以忽略后缀名
* */
resolve: {
modulesDirectories: ['node_modules', './node_modules'],
extensions: ['', '.js', '.jsx'],
unsafeCache: true,
alias: {
'component': path.resolve(__dirname, './src/component'),
'common': path.resolve(__dirname, './src/common'),
'framework': path.resolve(__dirname, './src/framework'),
'models': path.resolve(__dirname, './src/models'),
'page': path.resolve(__dirname, './src/page'),
'assets': path.resolve(__dirname, './src/assets'),
}
},
resolveLoader: {
modulesDirectories: ['node_modules', './node_modules']
},
entry: {
index: './src/index.js',
vendor: ['jquery', 'moment', 'classnames', 'react', 'react-dom', 'react-router', 'antd']
},
cache: true,
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/',
filename: '[name].[chunkHash:8].js',
chunkFilename: "[name].[chunkHash:8].js",
},
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel',
}, {
test: /\.css$/,
loader: 'style-loader!css-loader!postcss-loader',
// loader: ExtractTextPlugin.extract(['css', 'postcss'])
}, {
test: /\.scss$/,
loader: 'style-loader!css-loader!postcss-loader!sass-loader',
// loader: ExtractTextPlugin.extract(['css', 'postcss', 'sass'])
}, {
test: /\.less$/,
loader: 'style-loader!css-loader!postcss-loader!less-loader',
// loader: ExtractTextPlugin.extract(['css', 'postcss', 'less'])
}, {
test: /\.(png|jpg|jpeg|gif)$/i,
loader: 'url?name=[hash:8].[ext]&limit=8192',
}, {
//html模板加载器,可以处理引用的静态资源,默认配置参数attrs=img:src,处理图片的src引用的资源
//比如你配置,attrs=img:src img:data-src就可以一并处理data-src引用的资源了,就像下面这样
test: /\.html$/,
loader: "html?attrs=img:src img:data-src"
}, {
//文件加载器,处理文件静态资源
test: /\.(woff|woff2|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader?name=./fonts/[name].[ext]'
}, {
test: /\.json$/,
loader: 'json'
}
]
},
postcss: [
autoprefixer({browsers: ['last 3 versions', 'ie >= 9',]})
],
externals: {
// 'react': 'React',
// 'react-dom': 'ReactDOM',
// 'react-router': 'ReactRouter'
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': '"development"'
}
}),
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'windows.jQuery': 'jquery',
}),
// new ExtractTextPlugin('[name].[contenthash:8].css', {
// disable: false,
// allChunks: true
// }),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'],
minChunks: Infinity,
}),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /zh-cn/),
new HtmlWebpackPlugin({ //根据模板插入css/js成最终HTML
filename: './index.html', //生成的html存放路径,相对于path
template: './src/entry/index.html.ejs', //html模板路径
title: '凯贝姆Hi Baby管理后台',
favicon: './src/entry/bomb.ico',
inject: true, //js插入的位置,true/'head'/'body'/false
hash: false, //为静态资源生成hash值
minify: { //压缩HTML文件
removeComments: true, //移除HTML中的注释
collapseWhitespace: false //删除空白符与换行符
},
chunksSortMode: 'dependency',
externalsAssets: {
// react: '//cdn.bootcss.com/react/15.3.0/react.js',
// reactDOM: '//cdn.bootcss.com/react/15.3.0/react-dom.js',
// reactRouter: '//cdn.bootcss.com/react-router/2.6.1/ReactRouter.js'
}
})
]
}
module.exports = webpackConfig