2024-06-10 18:42:23 +03:00
|
|
|
import path from 'path';
|
|
|
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
|
|
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
|
|
|
import CopyPlugin from 'copy-webpack-plugin';
|
|
|
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
|
|
import * as url from 'url';
|
|
|
|
import { BUILD_ENVS } from './constants.js';
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
|
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
2018-08-30 17:25:33 +03:00
|
|
|
|
|
|
|
const RESOURCES_PATH = path.resolve(__dirname);
|
2024-06-10 18:42:23 +03:00
|
|
|
const ENTRY_REACT = path.resolve(RESOURCES_PATH, 'src/index.tsx');
|
|
|
|
const ENTRY_INSTALL = path.resolve(RESOURCES_PATH, 'src/install/index.tsx');
|
|
|
|
const ENTRY_LOGIN = path.resolve(RESOURCES_PATH, 'src/login/index.tsx');
|
2018-08-30 17:25:33 +03:00
|
|
|
const HTML_PATH = path.resolve(RESOURCES_PATH, 'public/index.html');
|
2019-01-18 19:29:51 +03:00
|
|
|
const HTML_INSTALL_PATH = path.resolve(RESOURCES_PATH, 'public/install.html');
|
2019-09-05 19:07:14 +03:00
|
|
|
const HTML_LOGIN_PATH = path.resolve(RESOURCES_PATH, 'public/login.html');
|
2020-05-14 14:45:16 +03:00
|
|
|
const ASSETS_PATH = path.resolve(RESOURCES_PATH, 'public/assets');
|
2018-08-30 17:25:33 +03:00
|
|
|
|
|
|
|
const PUBLIC_PATH = path.resolve(__dirname, '../build/static');
|
2020-05-14 14:45:16 +03:00
|
|
|
const PUBLIC_ASSETS_PATH = path.resolve(PUBLIC_PATH, 'assets');
|
2018-08-30 17:25:33 +03:00
|
|
|
|
2020-05-22 17:06:05 +03:00
|
|
|
const BUILD_ENV = BUILD_ENVS[process.env.BUILD_ENV];
|
|
|
|
|
2020-08-13 11:15:45 +03:00
|
|
|
const isDev = BUILD_ENV === BUILD_ENVS.dev;
|
|
|
|
|
2018-08-30 17:25:33 +03:00
|
|
|
const config = {
|
2020-05-22 17:06:05 +03:00
|
|
|
mode: BUILD_ENV,
|
2018-08-30 17:25:33 +03:00
|
|
|
target: 'web',
|
|
|
|
context: RESOURCES_PATH,
|
|
|
|
entry: {
|
2019-01-18 19:29:51 +03:00
|
|
|
main: ENTRY_REACT,
|
|
|
|
install: ENTRY_INSTALL,
|
2019-09-05 19:07:14 +03:00
|
|
|
login: ENTRY_LOGIN,
|
2018-08-30 17:25:33 +03:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: PUBLIC_PATH,
|
2024-06-10 18:42:23 +03:00
|
|
|
filename: '[name].[chunkhash].js',
|
2018-08-30 17:25:33 +03:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
modules: ['node_modules'],
|
2024-06-10 18:42:23 +03:00
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
2018-08-30 17:25:33 +03:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
2020-08-13 11:15:45 +03:00
|
|
|
{
|
|
|
|
test: /\.ya?ml$/,
|
|
|
|
type: 'json',
|
|
|
|
use: 'yaml-loader',
|
|
|
|
},
|
2018-08-30 17:25:33 +03:00
|
|
|
{
|
2020-05-22 17:06:05 +03:00
|
|
|
test: /\.css$/i,
|
|
|
|
use: [
|
2020-08-13 11:15:45 +03:00
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
},
|
2020-05-22 17:06:05 +03:00
|
|
|
{
|
2018-08-30 17:25:33 +03:00
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
},
|
2020-05-22 17:06:05 +03:00
|
|
|
],
|
2018-08-30 17:25:33 +03:00
|
|
|
},
|
|
|
|
{
|
2024-06-10 18:42:23 +03:00
|
|
|
test: /\.tsx?$/,
|
2018-08-30 17:25:33 +03:00
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2024-06-10 18:42:23 +03:00
|
|
|
loader: 'ts-loader',
|
2018-08-30 17:25:33 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
2020-05-22 17:06:05 +03:00
|
|
|
new CleanWebpackPlugin({
|
2018-10-12 15:20:59 +03:00
|
|
|
root: PUBLIC_PATH,
|
|
|
|
verbose: false,
|
|
|
|
dry: false,
|
|
|
|
}),
|
2018-08-30 17:25:33 +03:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
2018-10-09 10:25:21 +03:00
|
|
|
cache: false,
|
2019-01-18 19:29:51 +03:00
|
|
|
chunks: ['main'],
|
2018-08-30 17:25:33 +03:00
|
|
|
template: HTML_PATH,
|
|
|
|
}),
|
2019-01-18 19:29:51 +03:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
|
|
|
cache: false,
|
|
|
|
chunks: ['install'],
|
|
|
|
filename: 'install.html',
|
|
|
|
template: HTML_INSTALL_PATH,
|
|
|
|
}),
|
2019-09-05 19:07:14 +03:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
|
|
|
cache: false,
|
|
|
|
chunks: ['login'],
|
|
|
|
filename: 'login.html',
|
|
|
|
template: HTML_LOGIN_PATH,
|
|
|
|
}),
|
2020-05-22 17:06:05 +03:00
|
|
|
new MiniCssExtractPlugin({
|
2020-08-13 11:15:45 +03:00
|
|
|
filename: isDev ? '[name].css' : '[name].[hash].css',
|
|
|
|
chunkFilename: isDev ? '[id].css' : '[id].[hash].css',
|
2018-08-30 17:25:33 +03:00
|
|
|
}),
|
2020-05-22 17:06:05 +03:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: ASSETS_PATH,
|
|
|
|
to: PUBLIC_ASSETS_PATH,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2018-08-30 17:25:33 +03:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2024-06-10 18:42:23 +03:00
|
|
|
export default config;
|