-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.config.js
91 lines (88 loc) · 2.09 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
var webpack = require('webpack');
var webpackMd5Hash = require('webpack-md5-hash');
var path = require('path');
var htmlWebpackPlugin = require('html-webpack-plugin');
var openBrowserPlugin = require('open-browser-webpack-plugin');
var extractTextPlugin = require('extract-text-webpack-plugin');
var autoprefixer = require('autoprefixer');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: {
main: './src/index.js',
vendor: ['react', 'react-dom']
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'js/[name].js',
chunkFilename: 'js/[name].js',
},
module: {
rules: [
{
test: /\.less?$/,
use: extractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader?module',
'postcss-loader',
'less-loader'
],
publicPath: "../"
})
},
{
test: /\.js?$/,
exclude: path.resolve(__dirname, 'node_modules'),
use: {
loader: 'babel-loader',
options: {
presets: [['es2015', { modules: false }], 'react', 'stage-0'],
plugins: ['syntax-dynamic-import']
}
}
},
{
test: /\.(jpe?g|png|gif|svg)$/,
// use: ['url-loader?limit=40000&publicPath=images/&outputPath=images/&name=[name][hash:6].[ext]']
use: ['url-loader?limit=40000&name=images/[name][hash:6].[ext]']
}
]
},
plugins: [
new htmlWebpackPlugin({
filename: 'index.html',
title: 'anti-patterns-react'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
}),
new webpack.LoaderOptionsPlugin({
options: {
postcss: {
plugins: [
autoprefixer({
browsers: ['last 4 versions'],
flexbox: false
})
]
}
}
}),
new webpack.HotModuleReplacementPlugin(),
new webpackMd5Hash(),
new extractTextPlugin({
filename: 'style/index.css',
disable: true,
allChunks: true
})
],
devServer: {
// host: '0.0.0.0', 局域网访问需要这个
host: 'localhost',
port: '9999',
inline: true,
open: true,
historyApiFallback: true
}
}