-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
86 lines (75 loc) · 2.71 KB
/
Copy pathwebpack.config.ts
File metadata and controls
86 lines (75 loc) · 2.71 KB
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
import path from 'path';
import dotenv from 'dotenv';
import type { Configuration } from 'webpack';
import { WebpackMode, WebpackOptions, WebpackPaths } from './config/webpack/types/types';
import { webpackConfig } from './config/webpack/webpackConfig';
interface EnvVariables {
mock?: string;
ssl?: string;
mode: WebpackMode;
port?: number | string;
}
const modes = {
production: '.env.production',
development: '.env.development',
test: '.env.test',
};
export default (env: EnvVariables) => {
const paths: WebpackPaths = {
html: path.resolve(__dirname, 'public', 'index.html'),
output: path.resolve(__dirname, 'build'),
entry: path.resolve(__dirname, 'src', 'app', 'index.tsx'),
initTheme: path.resolve(
__dirname,
'src',
'features',
'theme',
'switch-theme',
'model',
'helpers',
'initTheme.ts',
),
src: path.resolve(__dirname, 'src'),
public: path.resolve(__dirname, 'public'),
env: path.resolve(__dirname, modes[env.mode]),
locales: path.resolve(__dirname, 'public', 'locales'),
buildLocales: path.resolve(__dirname, 'build', 'locales'),
httpsKey: path.resolve(__dirname, 'cert', 'localhost.key'),
httpsCert: path.resolve(__dirname, 'cert', 'localhost.crt'),
robots: path.resolve(__dirname, 'public', 'robots.txt'),
sitemap: path.resolve(__dirname, 'public', 'sitemap.xml'),
};
// Пытаемся загрузить .env файл, если он существует
try {
dotenv.config({ path: paths.env });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
// eslint-disable-next-line no-console
console.warn(`Warning: .env file not found for ${env.mode} mode. Using process.env values.`);
}
const isDev = env.mode === 'development';
const isMock = env.mode === 'development' && env.mock === 'true';
const notSsl = env.mode === 'development' && env.ssl === 'false';
const port = notSsl ? 3001 : (env.port ?? process.env.PORT ?? 3001);
// Добавляем DefinePlugin для передачи переменных окружения в приложение
const envVars = {
__IS_DEV__: JSON.stringify(isDev),
'process.env.NODE_ENV': JSON.stringify(env.mode),
'process.env.PORT': JSON.stringify(process.env.PORT || port),
'process.env.API_URL': JSON.stringify(process.env.API_URL),
'process.env.LANDING_URL': JSON.stringify(process.env.LANDING_URL),
'process.env.APP_URL': JSON.stringify(process.env.APP_URL),
'process.env.TELEGRAM_BOT_NAME': JSON.stringify(process.env.TELEGRAM_BOT_NAME),
'process.env.MOCK': JSON.stringify(isMock),
};
const options: WebpackOptions = {
port: +port,
mode: env.mode,
isDev,
paths,
envs: envVars,
notSsl,
};
const config: Configuration = webpackConfig(options);
return config;
};