-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.js
103 lines (101 loc) · 2.33 KB
/
webpack.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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const workbox = require('workbox-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const ExtractCssChunks = require("extract-css-chunks-webpack-plugin");
const config = {
entry: ['core-js/fn/promise', 'core-js/fn/array/find', 'whatwg-fetch', './src/index.js'],
mode: 'production',
output: {
path: __dirname + '/dist',
filename: 'scripts/[name].js',
},
optimization: {
splitChunks: {
chunks: 'initial',
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor'
}
}
}
},
module: {
rules: [
{
test: /\.js$/,
include: /(src)/,
use: [
{
loader: 'babel-loader',
},
],
},
{
test: /\.css$/,
include: /(src)/,
use: [
{
loader: ExtractCssChunks.loader,
options: {
hot: true,
reloadAll: true
},
},
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[name]__[local]--[hash:base64:5]',
},
},
{
loader: 'postcss-loader',
options: {
plugins: function () {
return [
require('precss'),
];
}
}
}
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader?name=/images/[name].[ext]'
]
}
],
},
plugins: [
new CleanWebpackPlugin(['dist']),
new CopyWebpackPlugin([
{
from: 'public'
}
]),
new ExtractCssChunks({
filename: '[name].css',
}),
new HtmlWebpackPlugin({
template: 'public/index.html',
}),
new workbox.GenerateSW({
swDest: 'service-worker.js',
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: 'http://i.imgur.com/**.{jpg,png}',
handler: 'cacheFirst',
},
]
}),
new CompressionPlugin(),
],
};
module.exports = config;