-
Notifications
You must be signed in to change notification settings - Fork 24
/
webpack.config.js
96 lines (90 loc) · 2.45 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
const { execSync } = require('child_process');
const path = require('path');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const moment = require('moment');
const sass = require('sass');
const webpack = require('webpack');
const WorkboxPlugin = require('workbox-webpack-plugin');
module.exports = (env, argv) => {
const basePath = __dirname;
const isProduction = argv.mode === 'production';
const commitHash = execSync('git rev-parse --short HEAD').toString();
const date = moment.utc().format('YYYY-MM-DD kk:mm:ss');
const faviconsWebpackPluginSettings = {
logo: path.resolve('src/images/icon.png'),
inject: true,
manifest: './src/manifest.webmanifest',
};
if (isProduction) {
faviconsWebpackPluginSettings.prefix = '.';
faviconsWebpackPluginSettings.publicPath = '.';
}
return {
entry: {
bundle: ['./src/index.jsx'],
},
devtool: isProduction ? undefined : 'source-map',
devServer: {
static: {
directory: basePath,
},
port: 8080,
},
resolve: {
extensions: ['.webpack.js', '.js', '.jsx', '.json', '.png'],
fallback: {
buffer: require.resolve('buffer'),
},
},
output: {
clean: true,
},
plugins: [
new FaviconsWebpackPlugin(faviconsWebpackPluginSettings),
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new webpack.DefinePlugin({
BUILD_DATE: JSON.stringify(date),
COMMIT_HASH: JSON.stringify(commitHash),
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
...(isProduction ? [new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [{
urlPattern: /https:\/\/raw\.githubusercontent\.com/,
handler: 'StaleWhileRevalidate',
}],
})] : []),
],
module: {
rules: [
{
test: /\.jsx?$/,
use: [
'babel-loader',
],
exclude: '/node_modules',
},
{
test: /\.(s*)css$/,
use: ['style-loader', 'css-loader', {
loader: 'sass-loader',
options: {
implementation: sass,
},
}],
},
{
test: /\.png$/,
type: 'asset/inline',
},
],
},
mode: isProduction ? 'production' : 'development',
};
};