-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
153 lines (148 loc) · 5.02 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
151
152
153
const webpack = require("webpack");
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const FilterWarningsPlugin = require("webpack-filter-warnings-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin");
const __IS_PRODUCTION__ = process.argv.mode === "production" || process.argv.includes("production");
const __IS_DEV__ = !__IS_PRODUCTION__;
const config = {
node: {
fs: "empty",
},
entry: "./src/js/application.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: __IS_PRODUCTION__ ? "bundle.[hash].js" : "[name].js",
},
module: {
rules: [
// wasm files should not be processed but just be emitted and we want
// to have their public URL.
{
test: /\.wasm$/,
type: "javascript/auto",
loader: "file-loader",
options: {
publicPath: "dist/",
},
},
{
test: /encoderWorker\.min\.js$/,
use: [{loader: 'file-loader'}]
},
{
test: /\.js$/,
use: [
"babel-loader",
// "eslint-loader",
],
exclude: [/node_modules/, /vendor/],
},
{
test: /\.worker\.js$/,
use: [
"worker-loader",
"babel-loader",
],
exclude: /node_modules/,
},
{
test: /\.s?css/i,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: __IS_DEV__,
reloadAll: true,
},
},
{
loader: "css-loader",
options: {
importLoaders: 2,
},
// query: {
// modules: {
// mode: "global",
// localIdentName: __IS_PRODUCTION__ ? "[hash:base64]" : "[name]__[local]",
// context: path.resolve(__dirname, "src/sass"),
// },
// localsConvention: "camelCase",
// },
},
{
loader: "sass-loader",
},
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: {
loader: "file-loader",
options: {
outputPath: "images",
name: "[name].[ext]",
},
},
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: {
loader: "file-loader",
options: {
outputPath: "fonts",
},
},
},
],
},
plugins: [
new WorkboxPlugin.GenerateSW(),
new CopyWebpackPlugin([{
from: "public",
}]),
new webpack.DefinePlugin({
__IS_PRODUCTION__: __IS_PRODUCTION__,
__IS_DEV__: __IS_DEV__,
}),
// new FlowWebpackPlugin(),
new MiniCssExtractPlugin({
filename: __IS_PRODUCTION__ ? "bundle.[hash].css" : "[name].css",
chunkFilename: "./src/sass/application.scss",
}),
new HtmlWebpackPlugin({template: "./src/index.html"}),
new CleanWebpackPlugin(),
__IS_PRODUCTION__ ? new CompressionPlugin({
filename: '[path].br[query]',
algorithm: 'brotliCompress',
compressionOptions: {level: 11},
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
}) : () => null,
__IS_PRODUCTION__ ? new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
threshold: 10240,
minRatio: 0.8,
}) : () => null,
// __IS_DEV__ ? new webpack.HotModuleReplacementPlugin({}) : () => null, // ламає код
],
optimization: {
minimize: __IS_PRODUCTION__,
minimizer: [new TerserPlugin(), new OptimizeCSSAssetsPlugin({})],
},
devServer: {
contentBase: path.join(__dirname, "dist"),
hot: true,
inline: true,
port: 8090,
},
};
module.exports = config;