1 |
0bb62f35
|
kohlicekjan
|
const pkg = require('./package.json')
|
2 |
|
|
|
3 |
|
|
const path = require('path')
|
4 |
|
|
const glob = require('glob')
|
5 |
|
|
const config = require('config')
|
6 |
|
|
const webpack = require('webpack')
|
7 |
|
|
|
8 |
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin')
|
9 |
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
10 |
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
11 |
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
12 |
|
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
13 |
|
|
const WebpackPwaManifest = require('webpack-pwa-manifest')
|
14 |
|
|
const WorkboxPlugin = require('workbox-webpack-plugin')
|
15 |
|
|
const PurifyCSSPlugin = require('purifycss-webpack')
|
16 |
|
|
const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin')
|
17 |
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
|
18 |
|
|
|
19 |
|
|
const isDev = process.argv.indexOf('development') > 0
|
20 |
|
|
|
21 |
|
|
const webpackConfig = {
|
22 |
|
|
entry: {
|
23 |
|
|
app: path.resolve(__dirname, 'src/app/app.js')
|
24 |
|
|
},
|
25 |
|
|
output: {
|
26 |
|
|
path: path.resolve(__dirname, 'dist'),
|
27 |
|
|
filename: 'app/[name].[hash].js',
|
28 |
|
|
publicPath: './',
|
29 |
|
|
sourceMapFilename: '[file].map'
|
30 |
|
|
},
|
31 |
|
|
devtool: isDev ? 'inline-source-map' : false,
|
32 |
|
|
module: {
|
33 |
|
|
rules: [
|
34 |
|
|
{
|
35 |
|
|
test: /\.(html|php)$/,
|
36 |
|
|
use: [
|
37 |
|
|
{
|
38 |
|
|
loader: 'html-loader',
|
39 |
|
|
options: { minimize: true }
|
40 |
|
|
}
|
41 |
|
|
]
|
42 |
|
|
},
|
43 |
|
|
{
|
44 |
|
|
test: /\.scss$/,
|
45 |
|
|
use: [
|
46 |
|
|
{
|
47 |
|
|
loader: MiniCssExtractPlugin.loader
|
48 |
|
|
},
|
49 |
|
|
{
|
50 |
|
|
loader: 'css-loader',
|
51 |
|
|
options: { sourceMap: true, minimize: true }
|
52 |
|
|
},
|
53 |
|
|
{
|
54 |
|
|
loader: 'postcss-loader'
|
55 |
|
|
},
|
56 |
|
|
{
|
57 |
|
|
loader: 'sass-loader',
|
58 |
|
|
options: { sourceMap: true }
|
59 |
|
|
}
|
60 |
|
|
],
|
61 |
|
|
include: [path.resolve(__dirname, 'src/assets/styles')]
|
62 |
|
|
},
|
63 |
|
|
{
|
64 |
|
|
test: /\.css$/,
|
65 |
|
|
use: [
|
66 |
|
|
{
|
67 |
|
|
loader: MiniCssExtractPlugin.loader
|
68 |
|
|
},
|
69 |
|
|
{
|
70 |
|
|
loader: 'css-loader',
|
71 |
|
|
options: { sourceMap: true, minimize: true }
|
72 |
|
|
}
|
73 |
|
|
],
|
74 |
|
|
include: [path.resolve(__dirname, 'src/assets/styles')]
|
75 |
|
|
},
|
76 |
|
|
{
|
77 |
|
|
test: /\.(png|jpg|gif)$/i,
|
78 |
|
|
use: [
|
79 |
|
|
{
|
80 |
|
|
loader: 'file-loader',
|
81 |
|
|
options: { name: 'assets/images/[name].[ext]' }
|
82 |
|
|
}
|
83 |
|
|
]
|
84 |
|
|
},
|
85 |
|
|
{
|
86 |
|
|
test: /\.(woff(2)?|ttf|eot|svg)$/,
|
87 |
|
|
use: [{
|
88 |
|
|
loader: 'file-loader',
|
89 |
|
|
options: { name: 'assets/fonts/[name].[ext]' }
|
90 |
|
|
}]
|
91 |
|
|
}
|
92 |
|
|
]
|
93 |
|
|
},
|
94 |
|
|
plugins: [
|
95 |
|
|
new CleanWebpackPlugin(['dist']),
|
96 |
|
|
new HtmlWebpackPlugin({
|
97 |
|
|
filename: 'index.php',
|
98 |
|
|
template: './src/index.template.php',
|
99 |
|
|
inject: 'head',
|
100 |
|
|
favicon: path.resolve(__dirname, 'src/assets/favicons/favicon.ico'),
|
101 |
|
|
minify: {
|
102 |
|
|
minifyCSS: true,
|
103 |
|
|
minifyJS: true,
|
104 |
|
|
collapseWhitespace: true,
|
105 |
|
|
collapseInlineTagWhitespace: true,
|
106 |
|
|
preserveLineBreaks: false,
|
107 |
|
|
removeAttributeQuotes: true,
|
108 |
|
|
removeComments: true
|
109 |
|
|
}
|
110 |
|
|
}),
|
111 |
|
|
new WebpackPwaManifest({
|
112 |
|
|
name: 'Průjezd vozidel - Plzeňský kraj',
|
113 |
|
|
short_name: 'PVPK',
|
114 |
|
|
description: 'Zobrazení dat o průjezdu vozidel pro Plzeňský kraj',
|
115 |
|
|
background_color: '#ffffff',
|
116 |
|
|
theme_color: '#ffffff',
|
117 |
|
|
icons: [
|
118 |
|
|
{
|
119 |
|
|
src: path.resolve(__dirname, 'src/assets/favicons/favicon.png'),
|
120 |
|
|
sizes: [24, 32, 48, 192, 512],
|
121 |
|
|
destination: path.join('assets', 'favicons')
|
122 |
|
|
}
|
123 |
|
|
],
|
124 |
|
|
ios: false,
|
125 |
|
|
inject: true,
|
126 |
|
|
fingerprints: false
|
127 |
|
|
}),
|
128 |
|
|
new WorkboxPlugin.GenerateSW({
|
129 |
|
|
swDest: 'sw.js',
|
130 |
|
|
importWorkboxFrom: 'local',
|
131 |
|
|
clientsClaim: true,
|
132 |
|
|
skipWaiting: true,
|
133 |
|
|
runtimeCaching: [
|
134 |
|
|
{
|
135 |
|
|
urlPattern: /\.(?:png|gif|jpg|jpeg|svg|ico|woff(2)?|ttf|eot)$/,
|
136 |
|
|
handler: 'cacheFirst'
|
137 |
|
|
},
|
138 |
|
|
{
|
139 |
|
|
urlPattern: /\.(?:css|js)$/,
|
140 |
|
|
handler: 'staleWhileRevalidate'
|
141 |
|
|
},
|
142 |
|
|
{
|
143 |
|
|
urlPattern: new RegExp('^' + config.API_URL + '.*$', 'i'),
|
144 |
|
|
handler: 'staleWhileRevalidate'
|
145 |
|
|
}
|
146 |
|
|
]
|
147 |
|
|
}),
|
148 |
|
|
new MiniCssExtractPlugin({
|
149 |
|
|
filename: 'assets/css/[name].[contenthash].css'
|
150 |
|
|
}),
|
151 |
|
|
new PurifyCSSPlugin({
|
152 |
|
|
paths: glob.sync(path.join(__dirname, 'src/**/*'))
|
153 |
|
|
}),
|
154 |
|
|
new webpack.ProvidePlugin({
|
155 |
|
|
$: 'jquery',
|
156 |
|
|
jquery: 'jquery',
|
157 |
|
|
jQuery: 'jquery',
|
158 |
|
|
'window.$': 'jquery',
|
159 |
|
|
'window.jQuery': 'jquery',
|
160 |
|
|
moment: 'moment',
|
161 |
|
|
'window.moment': 'moment'
|
162 |
|
|
}),
|
163 |
|
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
164 |
|
|
new webpack.DefinePlugin({
|
165 |
|
|
__VERSION__: JSON.stringify(pkg.version),
|
166 |
|
|
__API_URL__: JSON.stringify(config.API_URL),
|
167 |
|
|
__TOKEN_GENERATOR_PATH__: JSON.stringify(config.TOKEN_GENERATOR_PATH)
|
168 |
|
|
}),
|
169 |
|
|
new HtmlReplaceWebpackPlugin([
|
170 |
|
|
{
|
171 |
|
|
pattern: '__TOKEN_GENERATOR_PATH__',
|
172 |
|
|
replacement: JSON.stringify(config.TOKEN_GENERATOR_PATH)
|
173 |
|
|
}
|
174 |
|
|
]),
|
175 |
|
|
|
176 |
|
|
//new BundleAnalyzerPlugin()
|
177 |
|
|
],
|
178 |
|
|
optimization: {
|
179 |
|
|
minimize: !isDev,
|
180 |
|
|
minimizer: [
|
181 |
|
|
new UglifyJsPlugin({
|
182 |
|
|
uglifyOptions: {
|
183 |
|
|
output: {
|
184 |
|
|
comments: false,
|
185 |
|
|
beautify: false
|
186 |
|
|
}
|
187 |
|
|
}
|
188 |
|
|
}),
|
189 |
|
|
new OptimizeCSSAssetsPlugin({})
|
190 |
|
|
],
|
191 |
|
|
splitChunks: {
|
192 |
|
|
cacheGroups: {
|
193 |
|
|
commons: {
|
194 |
|
|
test: /[\\/]node_modules[\\/]/,
|
195 |
|
|
name: 'vendor',
|
196 |
|
|
chunks: 'all'
|
197 |
|
|
}
|
198 |
|
|
}
|
199 |
|
|
}
|
200 |
|
|
}
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
module.exports = webpackConfig
|