This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
150 lines (147 loc) · 4.25 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const postcss = require('postcss');
const postcssPluginsPost = require('./config/postcssPluginsPost');
const DIST_PATH = path.resolve(__dirname, 'dist');
const SRC_PATH = path.resolve(__dirname, 'src');
const NODE_MODULES_PATH = path.resolve(__dirname, 'node_modules');
module.exports = env => {
const isProduction = env && env.production;
return {
entry: {
index: path.join(SRC_PATH, 'index.jsx'),
},
output: {
path: DIST_PATH,
filename: '[name]_[hash].js',
publicPath: '/',
},
resolve: {
modules: [SRC_PATH, NODE_MODULES_PATH],
extensions: ['.js', '.jsx', '.css'],
},
mode: isProduction ? 'production' : 'development',
module: {
rules: [
{
test: /\.(woff|woff2)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'fonts/[name]_[hash].[ext]',
},
},
],
},
{
test: /\.(png|jpg|jpeg|gif)$/i,
use: [
{
loader: 'file-loader',
options: {
name: 'images/[name].[ext]',
},
},
],
},
{
test: /\.svg$/,
use: [{loader: 'svg-sprite-loader'}],
},
{
test: /(\.js|.jsx)$/,
include: [SRC_PATH, /node_modules\/style-guide/],
use: [{loader: 'babel-loader'}],
},
{
test: /\leaflet.css$/,
use: [{loader: 'style-loader'}, {loader: 'css-loader'}],
},
{
test: /\.css$/,
exclude: /\leaflet.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[local]',
camelCase: 'only',
minimize: isProduction,
},
},
'postcss-loader',
],
},
],
},
optimization: {
minimize: isProduction,
},
plugins: [
new HtmlWebpackPlugin({
filename: path.join(DIST_PATH, 'index.html'),
template: path.join(SRC_PATH, 'index.html'),
chunks: ['index'],
}),
new CopyWebpackPlugin([
{
from: path.join(SRC_PATH, 'images'),
to: path.join(DIST_PATH, 'images'),
},
{
from: path.join(NODE_MODULES_PATH, 'leaflet', 'dist', 'images'),
to: path.join(DIST_PATH, 'images'),
},
{
from: path.join(SRC_PATH, 'manifest.json'),
to: path.join(DIST_PATH, 'manifest.json'),
},
{
from: path.join(SRC_PATH, '.htaccess'),
to: path.join(DIST_PATH),
},
{
from: path.join(SRC_PATH, 'streets_en.json'),
to: path.join(DIST_PATH, 'streets_en.json'),
},
{
from: path.join(SRC_PATH, 'streets_pl.json'),
to: path.join(DIST_PATH, 'streets_pl.json'),
},
{
from: path.join(SRC_PATH, 'robots.txt'),
to: path.join(DIST_PATH, 'robots.txt'),
},
{
from: path.join(SRC_PATH, 'sitemap.xml'),
to: path.join(DIST_PATH, 'sitemap.xml'),
},
]),
new MiniCssExtractPlugin({
filename: '[name]_[hash].css',
chunkFilename: '[id]_[hash].css',
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/g,
cssProcessor: postcss(postcssPluginsPost({mode: isProduction})),
canPrint: true,
}),
new CleanWebpackPlugin(path.resolve(DIST_PATH, '*')),
new WorkboxPlugin.GenerateSW({
swDest: 'serviceWorker.js',
clientsClaim: true,
skipWaiting: true,
offlineGoogleAnalytics: true,
exclude: [/\.map$/, /^manifest.*\.js$/, /^.htaccess$/],
}),
],
};
};