-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
80 lines (79 loc) · 2.77 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
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
// const ExtracTextWebpackPlugin = require('extract-text-webpack-plugin')
const publicPath = '/';
const buildPath = 'build';
module.exports = {
entry: ['react-hot-loader/patch', 'babel-polyfill', path.resolve(__dirname, './src/index.js')],
output: {
path: path.resolve(__dirname, buildPath),
filename: 'build.js',
publicPath: publicPath
},
module: {
loaders: [
{
test: /\.js$/, // 配置要处理的文件格式,一般使用正则表达式匹配
loader: 'babel-loader', // 使用的加载器名称
// query: { // babel的配置参数,可以写在.babelrc文件里 也可以写在这
// presets: ['env', 'react']
// }
},
{
test: /\.(css|less)$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
{
loader: 'postcss-loader',
options: {
plugins: () => [
require('autoprefixer'),
// require('precss'),
require('postcss-flexbugs-fixes')
]
}
},
{
loader: 'less-loader'
}
]
},
{
test: [/\.gif$/,/\.jpe?g$/,/\.png$/],
loader: 'url-laoder',
options: {
limit: 10000, //1w字节以下大小的图片会自动转成base64
}
},
// {
// test: /\.(js|jsx)$/,
// enforce: 'pre', // 加载器的执行顺序,不设置为正常执行,pre(前),post(后),eslint是检查代码规范,应该在编译前就执行
// loader: 'eslint-loader'
// }
]
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html', // 指定模板路径
filename: 'index.html', // 指定文件名
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.UglifyJsPlugin()
],
devServer: {
contentBase: path.resolve(__dirname, buildPath),
publicPath: publicPath, //添加
port: '8081',
inline: true,
hot: true
}
}