-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-overrides.js
executable file
·123 lines (117 loc) · 3.04 KB
/
config-overrides.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
const { override, overrideDevServer, addPostcssPlugins, addWebpackAlias, addBundleVisualizer, addWebpackPlugin } = require('customize-cra');
const path = require('path');
const CompressionPlugin = require('compression-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const overrideDevServerConfig = () => config => {
config.setupMiddlewares = (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
return middlewares;
};
return {
...config,
allowedHosts: [
"aqua-book.ru",
"api.aqua-book.ru",
"it.aqua-book.ru",
"staging.aqua-book.ru",
],
};
};
const overrideWebpackConfig = (config, env) => {
const oneOfRule = config.module.rules.find(rule => Array.isArray(rule.oneOf));
if (oneOfRule) {
const sassRule = oneOfRule.oneOf.find(rule => rule.test && rule.test.toString().includes("sass|scss"));
if (sassRule) {
sassRule.use.push({
loader: require.resolve("sass-loader"),
options: {
additionalData: "@import './src/scss/globalscss/_global.scss';",
},
});
} else {
// Добавляем правило для SASS/SCSS файлов, если оно не найдено
oneOfRule.oneOf.push({
test: /\.(sass|scss)$/,
use: [
require.resolve('style-loader'),
require.resolve('css-loader'),
{
loader: require.resolve('sass-loader'),
options: {
additionalData: "@import './src/scss/globalscss/_global.scss';",
},
},
],
});
console.error("SASS rule was not found and has been added to 'oneOf' rules");
}
} else {
console.error("Cannot find 'oneOf' rule in Webpack config");
}
config.resolve = {
...config.resolve,
fallback: {
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"zlib": require.resolve("browserify-zlib"),
"stream": require.resolve("stream-browserify"),
}
};
if (env === 'production') {
config.optimization = {
...config.optimization,
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
},
},
}),
],
splitChunks: {
chunks: 'all',
maxInitialRequests: 30,
maxAsyncRequests: 30,
minSize: 10000,
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
};
config.plugins.push(new CompressionPlugin());
}
return config;
};
module.exports = {
webpack: override(
overrideWebpackConfig,
addPostcssPlugins([
require('tailwindcss'),
require('autoprefixer'),
]),
addWebpackAlias({
['@']: path.resolve(__dirname, 'src'),
}),
(config) => {
if (process.env.BUNDLE_VISUALIZE) {
config = addBundleVisualizer({ openAnalyzer: false })(config);
}
return config;
}
),
devServer: overrideDevServer(overrideDevServerConfig()),
};