This repository has been archived by the owner on Feb 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
executable file
·129 lines (111 loc) · 2.7 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
// Imports
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import WorkboxPlugin from 'workbox-webpack-plugin';
// Variables
const WEBPACK_MODE = process.env.WEBPACK_MODE || 'development';
const isDev = WEBPACK_MODE === 'development';
// Exports
module.exports = {
mode: WEBPACK_MODE,
watch: isDev,
watchOptions: { aggregateTimeout: 100 },
devtool: isDev ? 'eval' : 'source-map',
context: `${__dirname}/src`,
entry: {
sentry: './js/sentry',
preloader: './js/preloader',
dashboard: './js/dashboard',
},
output: {
library: 'WoodsAuc',
publicPath: '/',
filename: isDev
? './js/[name].[hash].js'
: './js/[name].[hash].min.js',
},
plugins: [
new CleanWebpackPlugin(),
isDev ? () => {
} : new TerserPlugin({
parallel: true,
terserOptions: {
ecma: 6,
},
}),
new MiniCssExtractPlugin({
filename: isDev
? './css/[name].[hash].css'
: './css/[name].[hash].min.css',
}),
new HtmlWebpackPlugin({
template: 'html/dashboard.pug',
}),
new CopyWebpackPlugin([
{
from: './img',
to: './img',
},
{
from: './light.mp3',
to: './light.mp3',
},
{
from: './manifest.json',
to: './manifest.json',
},
{
from: './browserconfig.xml',
to: './browserconfig.xml',
},
]),
new WorkboxPlugin.GenerateSW({
// Do not precache images
exclude: [/\.(?:png|jpg|jpeg|svg)$/],
// Define runtime caching rules.
runtimeCaching: [{
// Match any request that ends with .png, .jpg, .jpeg or .svg.
urlPattern: /\.(?:png|jpg|jpeg|svg)$/,
// Apply a cache-first strategy.
handler: 'CacheFirst',
options: {
// Use a custom cache name.
cacheName: 'images',
// Only cache 50 images.
expiration: {
maxEntries: 50,
},
},
}],
}),
],
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: isDev
? ['babel-loader', 'eslint-loader']
: ['babel-loader'],
}, {
test: /\.css$/,
exclude: /node_modules/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
],
}, {
test: /\.pug$/,
use: ['pug-loader'],
}],
},
devServer: {
contentBase: `${__dirname}/dist`,
compress: true,
port: 9000,
},
};