-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
204 lines (184 loc) · 4.58 KB
/
Copy pathwebpack.config.js
File metadata and controls
204 lines (184 loc) · 4.58 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
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
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const SriPlugin = require('webpack-subresource-integrity')
const IS_DEV = process.env.NODE_ENV === 'development'
const SRC_DIR = path.join(__dirname, 'src')
const BUILD_DIR = path.join(__dirname, 'build')
/**
* Webpack Configuration
*/
module.exports = {
devtool: IS_DEV ? 'source-map' : false,
devServer: {
publicPath: '/',
stats: 'errors-only',
noInfo: true,
lazy: false,
},
entry: {
'app': path.resolve(__dirname, 'src/index.js'),
},
output: IS_DEV ? {
pathinfo: true,
publicPath: 'http://localhost:3000/',
filename: '[name].js'
} : {
crossOriginLoading: 'anonymous',
path: BUILD_DIR,
filename: '[name].[hash:6].js',
chunkFilename: '[id].chunk.js',
publicPath: '',
},
resolve: {
modules: [
'node_modules',
path.join(__dirname, 'local_modules'),
SRC_DIR,
],
extensions: [ '.js', '.scss' ],
},
module: {
rules: ([
// BABEL
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
sourceMaps: 'inline',
},
},
{
test: require.resolve('alight'),
use: [
{
loader: 'expose-loader',
options: 'alight',
},
],
},
// CSS
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
},
// SCSS
{
test: /\.scss$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
localIdentName: IS_DEV ? '[local]__[hash:base64:3]' : '[hash:base64:6]',
sourceMap: IS_DEV,
},
},
{
loader: 'sass-loader',
options: {
// data: '@import "./scss/index";',
includePaths: [
SRC_DIR,
],
},
},
],
},
// IMAGES
{
test: /\.(jpe?g|png|gif)$/,
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
},
// FONTS
{
test: /.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/', // where the fonts will go
publicPath: '../', // override the default path
},
},
],
},
])
.map((rule) => {
if (IS_DEV) {
return rule
}
if (typeof rule.test !== 'string' && (rule.test.test('*.css') || rule.test.test('*.scss'))) {
rule.use = ExtractTextPlugin.extract({
fallback: 'style-loader',
use: rule.use.slice(1),
})
}
return rule
})
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new ProgressBarPlugin({ clear: false }),
new webpack.DefinePlugin({
IS_DEV,
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src/index.html'),
title: 'Swap',
inject: false,
hash: false,
files: {
js: [ 'vendor.js', 'app.js' ],
css: [ 'app.css' ],
}
}),
new SriPlugin({
hashFuncNames: [ 'sha256', 'sha384' ],
enabled: !IS_DEV,
}),
]
.concat(IS_DEV ? [] : [
new ExtractTextPlugin({
filename: '[name].[hash:6].css',
allChunks: true,
}),
new UglifyJsPlugin({
uglifyOptions: {
mangle: {
reserved: [
'Buffer',
'BigInteger',
'Point',
'ECPubKey',
'ECKey',
'sha512_asm',
'asm',
'ECPair',
'HDNode',
],
},
},
}),
// new CompressionPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
// this assumes your vendor imports exist in the node_modules directory
minChunks: (module) => module.context && module.context.indexOf('node_modules') >= 0,
}),
]),
}