-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
147 lines (144 loc) · 3.95 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
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const CssMinimizerWebpackPlugin = require('css-minimizer-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 port = 2233;
const dist = path.join(__dirname, 'dist');
const src = path.join(__dirname, 'src');
const host = 'localhost';
module.exports = (_, args) => {
const isProd = args.mode === 'production';
const isDev = args.mode === 'development';
const publicPath = isDev
? `http://${host}:${port}/`
: 'https://fashionit.amake.ru/assets/components/fashionit/';
return {
entry: './index.tsx',
devtool: isDev ? 'source-map' : undefined,
context: src,
devServer: isDev
? {
open: true,
port,
hot: true,
historyApiFallback: true,
host,
}
: undefined,
resolve: {
modules: [src, 'node_modules'],
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
alias: {
src,
},
preferAbsolute: true,
mainFiles: ['index'],
},
output: {
path: dist,
publicPath,
filename: `js/[name]_[contenthash].js`,
chunkFilename: `js/[name]_[contenthash].js`,
clean: true,
},
module: {
rules: [
{
test: /\.(js|ts)x?$/,
loader: require.resolve('babel-loader'),
exclude: /node_modules/,
},
{
test: /\.less$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
'css-loader',
'less-loader',
],
},
{
test: /\.(sc|sa|c)ss$/i,
use: [
{
loader: isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
modules: {
auto: /.module./,
localIdentName: isDev
? '[path][name]__[local]--[hash:base64:5]'
: '[hash:base64:8]',
},
},
},
'postcss-loader',
{
loader: 'sass-loader',
options: {
additionalData: '@import "src/shared/styles/index.scss";',
},
},
],
},
{
test: /\.svg$/i,
type: 'asset/resource',
resourceQuery: /url/, // *.svg?url
generator: {
filename: 'img/[name][ext]',
},
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
resourceQuery: { not: [/url/] }, // exclude react component if *.svg?url
use: ['@svgr/webpack'],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
favicon: './shared/assets/img/logo-amake.svg',
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: 'css/[name]_[contenthash].css',
chunkFilename: 'css/[name].css',
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: path.join(__dirname, 'tsconfig.json'),
},
}),
new webpack.DefinePlugin({
__IS_DEV__: JSON.stringify(isDev),
}),
...(isProd
? [
new CssMinimizerWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, 'public', 'locales'),
to: path.resolve(__dirname, 'dist', 'locales'),
},
],
}),
]
: []),
],
};
};