-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.js
136 lines (114 loc) · 2.59 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
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
const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
const srcPath = path.resolve('./src')
const imagePath = path.resolve('./dist/images')
const basePlugins =
[
new webpack.EnvironmentPlugin([ 'BUILD_ENV' ]),
new webpack.NoEmitOnErrorsPlugin(),
new ExtractTextPlugin({ filename: 'styles.css', disable: false, allChunks: true })
]
const browserSync = [
new BrowserSyncPlugin({
host: 'localhost',
port: 3100,
proxy: 'http://localhost:8080/'
}, {
reload: false
})
]
const devPlugins = [
new webpack.LoaderOptionsPlugin({
debug: true
}),
new webpack.HotModuleReplacementPlugin(),
...browserSync
]
const prodPlugins =
[
new webpack.optimize.UglifyJsPlugin({minimize: true})
]
const plugins = process.env.BUILD_ENV === 'production'
? basePlugins.concat(prodPlugins)
: basePlugins.concat(devPlugins)
const JSLoader = {
test: /\.js$/,
use: [
{
loader: 'babel-loader'
},
{
loader: 'eslint-loader'
}
],
include: __dirname,
exclude: /node_modules/
}
const SASSLoader = {
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
loader: 'css-loader!sass-loader'
})
}
const CSSLoader = {
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: 'css-loader'
})
}
const ImageLoader = {
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
const environmentOptions =
process.env.BUILD_ENV === 'production'
? { }
: { devtool: 'eval' }
const devEntry = [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server'
]
const defaultEntry = [path.join(srcPath, 'app.js')]
const entry =
process.env.BUILD_ENV === 'production'
? defaultEntry
: devEntry.concat(defaultEntry)
module.exports = {
plugins,
...environmentOptions,
entry,
output: {
path: path.resolve('./dist'),
filename: 'bundle.js',
publicPath: 'http://localhost:8080/'
},
devServer: {
hot: true,
stats: {colors: true},
contentBase: path.resolve('./dist'),
historyApiFallback: true
},
module: {
rules: [
JSLoader,
SASSLoader,
CSSLoader,
ImageLoader
]
},
resolve: {
alias: {
component: srcPath + '/component',
driver: srcPath + '/driver',
page: srcPath + '/page',
util: srcPath + '/util',
images: imagePath
}
}
}