-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.babel.js
117 lines (113 loc) · 3.2 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
import path from 'path';
import webpack from 'webpack';
import HtmlPlugin from 'html-webpack-plugin';
import htmlTemplate from 'html-webpack-template';
import FaviconsPlugin from 'favicons-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CopyPlugin from 'copy-webpack-plugin';
const port = process.env.PORT || 55577;
export default (env, argv) => {
const { mode } = argv;
return {
context: path.resolve(__dirname, 'src'),
entry: {
index: ['core-js/stable', 'regenerator-runtime/runtime', './index.js']
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: `[name].${mode === 'production' ? '[chunkhash:6].' : ''}js`,
publicPath: '/'
},
devtool: mode === 'development' ? 'source-map' : false,
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
port,
historyApiFallback: true
},
resolve: {
symlinks: false,
modules: ['node_modules'],
extensions: ['.js', '.jsx']
},
resolveLoader: {
modules: ['node_modules'],
moduleExtensions: ['.js']
},
module: {
rules: [{
test: /\.jsx?$/,
use: 'babel-loader',
include: path.resolve(__dirname, 'src')
}, {
test: /\.(sa|sc|c)ss$/,
use: [
{ loader: MiniCssExtractPlugin.loader, options: { publicPath: '../' } },
'css-loader',
'postcss-loader',
{ loader: 'resolve-url-loader', options: { keepQuery: true } },
'sass-loader'
]
}, {
test: /\.(jpg|png)$/,
use: {
loader: 'file-loader',
options: {
name: 'img/[name].[hash:6].[ext]'
}
}
}]
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
name: 'vendor',
test: /node_modules/,
chunks: 'initial',
enforce: true
}
}
},
runtimeChunk: true
},
performance: {
maxEntrypointSize: 1024 * 1024,
maxAssetSize: 1024 * 1024
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new HtmlPlugin({
filename: path.resolve(__dirname, 'dist/index.html'),
inject: false,
template: htmlTemplate,
title: 'Storekeeper',
meta: [{
name: 'viewport',
content: 'width=device-width, initial-scale=1'
}, {
'http-equiv': 'Cache-Control',
content: 'no-cache, no-store, must-revalidate'
}, {
'http-equiv': 'Pragma',
content: 'no-cache'
}, {
'http-equiv': 'Expires',
content: '0'
}],
appMountId: 'container',
minify: {
collapseWhitespace: mode === 'production'
}
}),
new FaviconsPlugin(path.resolve(__dirname, 'storekeeper.png')),
new MiniCssExtractPlugin({
filename: `css/${mode === 'development' ? '[name].css' : '[name].[hash:6].css'}`,
chunkFilename: `css/${mode === 'development' ? '[name].css' : '[name].[hash:6].css'}`
}),
new CopyPlugin([{
from: path.resolve(__dirname, 'src/levels'),
to: path.resolve(__dirname, 'dist/levels')
}])
]
};
};