-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
176 lines (159 loc) · 4.27 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { EsbuildPlugin } = require('esbuild-loader');
const ESLintPlugin = require('eslint-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
const { baseUrl } = require('./config.json');
let alias = {};
try {
const getAliases = require('./@nextgis/packages/build-tools/lib/aliases.cjs');
alias = getAliases();
} catch {
console.log('Aliases not loaded');
}
module.exports = (env, argv) => {
const isProd = argv.mode === 'production';
const plugins = [
new CopyPlugin({ patterns: [{ from: 'font', to: 'font' }] }),
new FaviconsWebpackPlugin('./src/img/favicon.png'),
new HtmlWebpackPlugin({
template: 'src/index.html',
// favicon: 'src/images/favicon.ico',
}),
new ForkTsCheckerWebpackPlugin({
async: false,
}),
new ESLintPlugin({
extensions: ['js', 'jsx', 'ts', 'tsx'],
fix: true,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(argv.mode || 'development'),
__BROWSER__: true,
__DEV__: !isProd,
}),
];
if (isProd) {
// const BundleAnalyzerPlugin =
// require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
plugins.push(
...[
// new BundleAnalyzerPlugin(),
new MiniCssExtractPlugin(),
new CompressionPlugin(),
],
);
}
const config = {
mode: 'development',
devtool: isProd ? 'source-map' : 'inline-source-map',
entry: {
main: ['./src/main.ts'],
},
output: {
filename: '[name][hash:7].js',
publicPath: '/',
},
resolve: {
modules: [path.resolve(__dirname, 'node_modules')],
extensions: ['.js', '.ts', '.json'],
alias,
},
module: {
rules: [
{
test: /\.(ts|js)x?$/i,
exclude: /node_modules/,
use: {
loader: 'esbuild-loader',
options: {
loader: 'ts', // Or 'ts' if you don't need tsx
target: 'es2015',
},
},
},
{
test: /\.css$/i,
use: [
isProd ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
],
},
{
test: /\.(scss)$/,
use: [
isProd ? MiniCssExtractPlugin.loader : 'style-loader',
{
loader: 'css-loader',
options: { sourceMap: true }, // translates CSS into CommonJS modules
},
{
loader: 'postcss-loader', // Run post css actions
options: {
sourceMap: true,
postcssOptions: {
plugins: function () {
// post css plugins, can be exported to postcss.config.js
return [require('precss'), require('autoprefixer')];
},
},
},
},
{
loader: 'sass-loader', // compiles Sass to CSS
options: { sourceMap: true },
},
],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
{
test: /\.csv$/,
loader: 'csv-loader',
options: {
dynamicTyping: true,
header: true,
skipEmptyLines: true,
},
},
],
},
plugins,
devServer: {
historyApiFallback: true,
hot: true,
proxy: [
{
context: ['/api'],
target: baseUrl,
},
],
},
optimization: {
minimize: isProd,
minimizer: [
new EsbuildPlugin({
target: 'es2015',
}),
],
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
minSize: 10000,
maxSize: 250000,
},
},
};
return config;
};