-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
110 lines (107 loc) · 3.24 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
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 ESLintPlugin = require('eslint-webpack-plugin')
const isProduction = process.env.NODE_ENV === 'production'
// console.log('isProduction', isProduction)
const styleLoaderHandler = isProduction ? MiniCssExtractPlugin.loader : 'style-loader'
module.exports = {
// mode: 'production',
entry: path.resolve(__dirname, 'src', 'index.ts'),
// entry: path.resolve(__dirname, 'typescript', '5.generics.ts'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name][contenthash].js',
clean: true,
assetModuleFilename: 'assets/[name][hash][ext]'
},
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: [".ts", ".tsx", ".js"],
// Add support for TypeScripts fully qualified ESM imports.
extensionAlias: {
".js": [".js", ".ts"],
".cjs": [".cjs", ".cts"],
".mjs": [".mjs", ".mts"]
}
},
devtool: (isProduction) ? 'source-map' : 'inline-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]',
},
},
// all files with a `.ts`, `.cts`, `.mts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.([cm]?ts|tsx)$/, loader: "ts-loader" },
{
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'),
filename: 'index.html',
favicon: path.resolve(__dirname, 'src', 'img', 'note.svg'),
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',
// }),
new ESLintPlugin({
extensions: ['js', 'ts'],
// fix: true,
}),
],
}