-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
91 lines (88 loc) · 2.53 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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
// const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const isProduction = process.env.NODE_ENV === 'production'
const styleLoaderHandler = isProduction ? MiniCssExtractPlugin.loader : 'style-loader'
module.exports = {
// mode: 'production',
entry: path.resolve(__dirname, 'src', 'index.js'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name][contenthash].js',
clean: true,
assetModuleFilename: 'assets/[name][hash][ext]',
},
devtool: (isProduction) ? 'source-map' : 'eval-source-map',
devServer: {
static: {
directory: path.resolve(__dirname, 'dist'),
},
host: 'localhost',
port: 3000,
open: true,
hot: true,
compress: true,
historyApiFallback: true,
onListening: function(devServer){
if(isProduction){
throw new Error('webpack-dev-server is not allowed')
}
const port = devServer.server.address().port
console.log(`Port: ${port}`)
},
},
module: {
rules: [
{
test: /\.s?css$/i,
use: [styleLoaderHandler, "css-loader", 'sass-loader'],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/[hash][ext]',
},
},
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
cacheDirectory: true,
presets: ['@babel/preset-env'],
}
}
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'template.html'),
favicon: path.resolve(__dirname, 'src', 'img', 'note.svg'),
filename: 'index.html',
title: 'Приложение для электронных чеков v1.0.0',
}),
// new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: 'css/[name][contenthash].css',
}),
new BundleAnalyzerPlugin({
analyzerMode: 'static',
defaultSizes: 'gzip',
analyzerPort: 3001,
reportTitle: 'Основной отчет',
reportFilename: 'stats.html',
openAnalyzer: false,
generateStatsFile: true,
statsFilename: 'stats.json',
}),
],
}