2018-08-30 17:25:33 +03:00
|
|
|
const path = require('path');
|
|
|
|
const autoprefixer = require('autoprefixer');
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const flexBugsFixes = require('postcss-flexbugs-fixes');
|
2018-10-12 15:20:59 +03:00
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
2019-03-12 18:59:58 +03:00
|
|
|
const CopyPlugin = require('copy-webpack-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');
|
2019-05-31 16:36:48 +03:00
|
|
|
const FAVICON_PATH = path.resolve(RESOURCES_PATH, 'public/favicon.png');
|
2018-08-30 17:25:33 +03:00
|
|
|
|
|
|
|
const PUBLIC_PATH = path.resolve(__dirname, '../build/static');
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
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: [
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
fallback: 'style-loader',
|
|
|
|
use: [{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
plugins: () => [
|
|
|
|
flexBugsFixes,
|
|
|
|
autoprefixer({
|
|
|
|
browsers: [
|
|
|
|
'>1%',
|
|
|
|
'last 4 versions',
|
|
|
|
'Firefox ESR',
|
|
|
|
'not ie < 9',
|
|
|
|
],
|
|
|
|
flexbox: 'no-2009',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: true,
|
|
|
|
presets: [
|
|
|
|
['env', {
|
|
|
|
modules: false,
|
|
|
|
}],
|
|
|
|
'react',
|
|
|
|
'stage-2',
|
|
|
|
],
|
|
|
|
plugins: ['transform-runtime', 'transform-object-rest-spread'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
exclude: [/\.js$/, /\.html$/, /\.json$/, /\.css$/],
|
|
|
|
use: {
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
fallback: 'file-loader',
|
|
|
|
name: 'media/[name].[hash:8].[ext]',
|
|
|
|
limit: 10 * 1024,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
|
|
}),
|
2020-01-31 15:57:20 +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,
|
|
|
|
}),
|
2018-08-30 17:25:33 +03:00
|
|
|
new ExtractTextPlugin({
|
2018-10-09 10:25:21 +03:00
|
|
|
filename: '[name].[contenthash].css',
|
2018-08-30 17:25:33 +03:00
|
|
|
}),
|
2019-03-12 18:59:58 +03:00
|
|
|
new CopyPlugin([
|
|
|
|
{ from: FAVICON_PATH, to: PUBLIC_PATH },
|
|
|
|
]),
|
2018-08-30 17:25:33 +03:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = config;
|