-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
101 lines (97 loc) · 2.83 KB
/
webpack.config.js
File metadata and controls
101 lines (97 loc) · 2.83 KB
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
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: require.resolve('react'),
loader: 'expose-loader?React'
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader'
},
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
localIdentName: '[name]_[local]_[hash:base64]',
sourceMap: true,
minimize: true
}
}
]
},
{
test: /\.(eot|woff2?|ttf|otf)(\?.*)?$/i,
loader: 'url-loader?limit=5120&name=[path][name].[hash].[ext]'
},
{
test: /\.(jpe?g|webm|mp4|png|gif)(\?.*)?$/i,
loader:
'url-loader?limit=5120&name=[path][name].[hash].[ext]!img-loader'
},
{
test: /\.svg$/,
loader: 'raw-loader'
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: './src/index.html',
filename: './index.html'
}),
new CleanWebpackPlugin(path.join(__dirname, 'dist')),
new ManifestPlugin({
fileName: 'asset-manifest.json'
}),
new SWPrecacheWebpackPlugin({
// By default, a cache-busting query parameter is appended to requests
// used to populate the caches, to ensure the responses are fresh.
// If a URL is already hashed by Webpack, then there is no concern
// about it being stale, and the cache-busting can be skipped.
dontCacheBustUrlsMatching: /\.\w{8}\./,
filename: 'service-worker.js',
logger(message) {
if (message.indexOf('Total precache size is') === 0) {
// This message occurs for every build and is a bit too noisy.
return;
}
console.log(message);
},
minify: true, // minify and uglify the script
navigateFallback: '/index.html',
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/]
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.html$ |\.css$/,
threshold: 10240,
minRatio: 0.8
}),
new CopyWebpackPlugin([
{ from: 'src/pwa' } // define the path of the files to be copied
])
]
};