2018-08-30 17:25:33 +03:00
|
|
|
const path = require('path');
|
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const flexBugsFixes = require('postcss-flexbugs-fixes');
|
2020-05-22 17:06:05 +03:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
2019-03-12 18:59:58 +03:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
2020-05-22 17:06:05 +03:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2018-08-30 17:25:33 +03:00
|
|
|
|
|
|
|
const RESOURCES_PATH = path.resolve(__dirname);
|
|
|
|
const ENTRY_REACT = path.resolve(RESOURCES_PATH, 'src/index.js');
|
2019-01-18 19:29:51 +03:00
|
|
|
const ENTRY_INSTALL = path.resolve(RESOURCES_PATH, 'src/install/index.js');
|
2019-09-05 19:07:14 +03:00
|
|
|
const ENTRY_LOGIN = path.resolve(RESOURCES_PATH, 'src/login/index.js');
|
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_ENVS = {
|
|
|
|
dev: 'development',
|
|
|
|
prod: 'production',
|
|
|
|
};
|
|
|
|
|
|
|
|
const BUILD_ENV = BUILD_ENVS[process.env.BUILD_ENV];
|
|
|
|
|
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,
|
2018-10-09 10:25:21 +03:00
|
|
|
filename: '[name].[chunkhash].js',
|
2018-08-30 17:25:33 +03:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
modules: ['node_modules'],
|
2020-01-31 15:57:20 +03:00
|
|
|
alias: {
|
|
|
|
MainRoot: path.resolve(__dirname, '../'),
|
|
|
|
ClientRoot: path.resolve(__dirname, './src'),
|
|
|
|
},
|
2018-08-30 17:25:33 +03:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2020-05-22 17:06:05 +03:00
|
|
|
test: /\.css$/i,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{
|
2018-08-30 17:25:33 +03:00
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
plugins: () => [
|
|
|
|
flexBugsFixes,
|
|
|
|
autoprefixer({
|
|
|
|
flexbox: 'no-2009',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2020-05-22 17:06:05 +03:00
|
|
|
],
|
2018-08-30 17:25:33 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
exclude: [/\.js$/, /\.html$/, /\.json$/, /\.css$/],
|
|
|
|
use: {
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
fallback: 'file-loader',
|
|
|
|
name: 'media/[name].[hash:8].[ext]',
|
|
|
|
limit: 10 * 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
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({
|
2018-10-09 10:25:21 +03:00
|
|
|
filename: '[name].[contenthash].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
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = config;
|