2018-08-30 15:25:33 +01:00
|
|
|
const path = require('path');
|
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const flexBugsFixes = require('postcss-flexbugs-fixes');
|
2020-05-22 15:06:05 +01:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
2019-03-12 15:59:58 +00:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
2020-05-22 15:06:05 +01:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2020-08-13 09:15:45 +01:00
|
|
|
const { BUILD_ENVS } = require('./constants');
|
2018-08-30 15:25:33 +01:00
|
|
|
|
|
|
|
const RESOURCES_PATH = path.resolve(__dirname);
|
|
|
|
const ENTRY_REACT = path.resolve(RESOURCES_PATH, 'src/index.js');
|
2019-01-18 16:29:51 +00:00
|
|
|
const ENTRY_INSTALL = path.resolve(RESOURCES_PATH, 'src/install/index.js');
|
2019-09-05 17:07:14 +01:00
|
|
|
const ENTRY_LOGIN = path.resolve(RESOURCES_PATH, 'src/login/index.js');
|
2018-08-30 15:25:33 +01:00
|
|
|
const HTML_PATH = path.resolve(RESOURCES_PATH, 'public/index.html');
|
2019-01-18 16:29:51 +00:00
|
|
|
const HTML_INSTALL_PATH = path.resolve(RESOURCES_PATH, 'public/install.html');
|
2019-09-05 17:07:14 +01:00
|
|
|
const HTML_LOGIN_PATH = path.resolve(RESOURCES_PATH, 'public/login.html');
|
2020-05-14 12:45:16 +01:00
|
|
|
const ASSETS_PATH = path.resolve(RESOURCES_PATH, 'public/assets');
|
2018-08-30 15:25:33 +01:00
|
|
|
|
|
|
|
const PUBLIC_PATH = path.resolve(__dirname, '../build/static');
|
2020-05-14 12:45:16 +01:00
|
|
|
const PUBLIC_ASSETS_PATH = path.resolve(PUBLIC_PATH, 'assets');
|
2018-08-30 15:25:33 +01:00
|
|
|
|
2020-05-22 15:06:05 +01:00
|
|
|
const BUILD_ENV = BUILD_ENVS[process.env.BUILD_ENV];
|
|
|
|
|
2020-08-13 09:15:45 +01:00
|
|
|
const isDev = BUILD_ENV === BUILD_ENVS.dev;
|
|
|
|
|
2018-08-30 15:25:33 +01:00
|
|
|
const config = {
|
2020-05-22 15:06:05 +01:00
|
|
|
mode: BUILD_ENV,
|
2018-08-30 15:25:33 +01:00
|
|
|
target: 'web',
|
|
|
|
context: RESOURCES_PATH,
|
|
|
|
entry: {
|
2019-01-18 16:29:51 +00:00
|
|
|
main: ENTRY_REACT,
|
|
|
|
install: ENTRY_INSTALL,
|
2019-09-05 17:07:14 +01:00
|
|
|
login: ENTRY_LOGIN,
|
2018-08-30 15:25:33 +01:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: PUBLIC_PATH,
|
2020-08-13 09:15:45 +01:00
|
|
|
filename: '[name].[hash].js',
|
2018-08-30 15:25:33 +01:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
modules: ['node_modules'],
|
2020-01-31 12:57:20 +00:00
|
|
|
alias: {
|
|
|
|
MainRoot: path.resolve(__dirname, '../'),
|
|
|
|
ClientRoot: path.resolve(__dirname, './src'),
|
2020-09-01 14:30:30 +01:00
|
|
|
// TODO: uncomment when v16.13.1 is released https://stackoverflow.com/a/62671689/12942752
|
|
|
|
// 'react-dom': '@hot-loader/react-dom',
|
2020-01-31 12:57:20 +00:00
|
|
|
},
|
2018-08-30 15:25:33 +01:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
2020-08-13 09:15:45 +01:00
|
|
|
{
|
|
|
|
test: /\.ya?ml$/,
|
|
|
|
type: 'json',
|
|
|
|
use: 'yaml-loader',
|
|
|
|
},
|
2018-08-30 15:25:33 +01:00
|
|
|
{
|
2020-05-22 15:06:05 +01:00
|
|
|
test: /\.css$/i,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
2020-08-13 09:15:45 +01:00
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {
|
|
|
|
hmr: isDev,
|
|
|
|
},
|
|
|
|
},
|
2020-05-22 15:06:05 +01:00
|
|
|
{
|
2018-08-30 15:25:33 +01:00
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
plugins: () => [
|
|
|
|
flexBugsFixes,
|
|
|
|
autoprefixer({
|
|
|
|
flexbox: 'no-2009',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2020-05-22 15:06:05 +01:00
|
|
|
],
|
2018-08-30 15:25:33 +01: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 15:06:05 +01:00
|
|
|
new CleanWebpackPlugin({
|
2018-10-12 13:20:59 +01:00
|
|
|
root: PUBLIC_PATH,
|
|
|
|
verbose: false,
|
|
|
|
dry: false,
|
|
|
|
}),
|
2018-08-30 15:25:33 +01:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
2018-10-09 08:25:21 +01:00
|
|
|
cache: false,
|
2019-01-18 16:29:51 +00:00
|
|
|
chunks: ['main'],
|
2018-08-30 15:25:33 +01:00
|
|
|
template: HTML_PATH,
|
|
|
|
}),
|
2019-01-18 16:29:51 +00:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
|
|
|
cache: false,
|
|
|
|
chunks: ['install'],
|
|
|
|
filename: 'install.html',
|
|
|
|
template: HTML_INSTALL_PATH,
|
|
|
|
}),
|
2019-09-05 17:07:14 +01:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
inject: true,
|
|
|
|
cache: false,
|
|
|
|
chunks: ['login'],
|
|
|
|
filename: 'login.html',
|
|
|
|
template: HTML_LOGIN_PATH,
|
|
|
|
}),
|
2020-05-22 15:06:05 +01:00
|
|
|
new MiniCssExtractPlugin({
|
2020-08-13 09:15:45 +01:00
|
|
|
filename: isDev ? '[name].css' : '[name].[hash].css',
|
|
|
|
chunkFilename: isDev ? '[id].css' : '[id].[hash].css',
|
2018-08-30 15:25:33 +01:00
|
|
|
}),
|
2020-05-22 15:06:05 +01:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: ASSETS_PATH,
|
|
|
|
to: PUBLIC_ASSETS_PATH,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
2018-08-30 15:25:33 +01:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = config;
|