-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
210 lines (201 loc) · 5.16 KB
/
webpack.config.babel.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
import { argv } from 'yargs';
import { getIfUtils, removeEmpty } from 'webpack-config-utils';
import { join, resolve } from 'path';
import chalk from 'chalk';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import jsonImporter from 'node-sass-json-importer';
import LiveReloadPlugin from 'webpack-livereload-plugin';
import ProgressBarPlugin from 'progress-bar-webpack-plugin';
import shapes from './shared/data/svgs.json';
import webpack from 'webpack';
import WebpackCleanupPlugin from 'webpack-cleanup-plugin';
const config = env => {
const { ifProd, ifNotProd } = getIfUtils(env);
const minify = {
collapseWhitespace: true,
keepClosingSlash: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
showErrors: true
};
const mode = ifProd('production', 'development');
const progress = {
bar: chalk.green(':bar'),
status: chalk.cyan(':percent')
};
let agent = {
'browser': {
'name': 'Chrome',
'version': '65.0.3325.162',
'major': '65'
},
'cpu': {},
'device': {},
'engine': {
'name': 'WebKit',
'version': '537.36'
},
'os': {
'name': 'Mac OS',
'version': '10.13.3'
}
};
let sourceMap = !ifProd();
let ua = [
'Chrome/65.0.3325.162',
'Safari/537.36',
'Mozilla/5.0',
'(Macintosh; Intel Mac OS X 10_13_3)',
'AppleWebKit/537.36 (KHTML, like Gecko)'
];
agent.ua = ua.join(' ');
const configVars = {
baseUrl: JSON.stringify('/'),
envVars: {
GIPHY_KEY: JSON.stringify(argv.GIPHY_KEY)
},
host: JSON.stringify('build'),
originalUrl: JSON.stringify('/'),
'process.env.NODE_ENV': JSON.stringify(mode),
shapes: JSON.stringify(shapes),
tagOptions: false,
uaName: JSON.stringify(agent)
};
const envConfig = {
devServer: {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS'
},
historyApiFallback: true,
hot: true,
publicPath: '/',
stats: {
assets: false,
cached: false,
cachedAssets: false,
children: false,
chunks: false,
chunkModules: false,
chunkOrigins: false,
colors: true,
depth: false,
entrypoints: false,
errors: true,
errorDetails: true,
hash: false,
maxModules: 0,
modules: false,
performance: false,
providedExports: false,
publicPath: false,
reasons: false,
source: false,
timings: false,
usedExports: false,
version: false,
warnings: false
}
},
devtool: ifProd(false, 'cheap-eval-source-map'),
entry: [
resolve(__dirname, 'server/styles/main.scss'),
resolve(__dirname, 'src/index')
],
mode,
module: {
rules: [
{
test: /\.pug$/,
use: 'pug-loader'
},
{
test: /\.json$/,
include: '/shared/data',
loader: 'json-loader'
},
{
enforce: 'pre',
test: /\.jsx?$/,
loader: 'eslint-loader',
exclude: /node_modules/
},
{
test: /\.jsx?$/,
include: resolve(__dirname, 'src'),
loader: 'babel-loader'
},
{
test: /\.(gif|ico|jpe?g|png)$/i,
loader: 'file-loader?name=[name].[ext]'
},
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
{
test: /(\.css|\.scss)$/,
loaders: [
{
loader: 'style-loader',
options: { sourceMap }
},
{
loader: 'css-loader',
options: { sourceMap }
},
{
loader: 'sass-loader',
options: {
importer: jsonImporter(),
sourceMap
}
}
]
}
]
},
output: {
path: resolve(__dirname, 'dist'),
pathinfo: ifNotProd(),
publicPath: '/',
filename: 'bundle.js'
},
performance: { hints: false },
plugins: removeEmpty([
ifProd(new ExtractTextPlugin('[name].[contenthash].css')),
new HtmlWebpackPlugin({
inject: false,
minify: ifProd(minify, false),
sourceMap: false,
template: 'server/views/index.pug'
}),
ifNotProd(new LiveReloadPlugin({ appendScriptTag: true })),
new ProgressBarPlugin({
clear: false,
format: ` ${progress.bar} ${progress.status} (:elapsed sec) \r`
}),
new webpack.DefinePlugin(configVars)
]),
resolve: {
extensions: ['.js', '.jsx', '.json'],
},
target: 'web'
};
if (env.debug) {
console.log(envConfig);
debugger; // eslint-disable-line
}
return envConfig;
};
export default config;