Pull request: beta client squashed
Merge in DNS/adguard-home from beta-client-2 to master
Squashed commit of the following:
commit b2640cc49a6c5484d730b534dcf5a8013d7fa478
Merge: 659def862 aef4659e9
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Dec 29 19:23:09 2020 +0300
Merge branch 'master' into beta-client-2
commit 659def8626467949c35b7a6a0c99ffafb07b4385
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Dec 29 17:25:14 2020 +0300
all: upgrade github actions node version
commit b4b8cf8dd75672e9155da5d111ac66e8f5ba1535
Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com>
Date: Tue Dec 29 16:57:14 2020 +0300
all: beta client squashed
This commit is contained in:
40
client2/scripts/webpack/helpers.js
Normal file
40
client2/scripts/webpack/helpers.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const yaml = require('yaml');
|
||||
const fs = require('fs');
|
||||
|
||||
const ZERO_HOST = '0.0.0.0';
|
||||
const LOCALHOST = '127.0.0.1';
|
||||
const DEFAULT_PORT = 80;
|
||||
|
||||
const importConfig = () => {
|
||||
try {
|
||||
const doc = yaml.parse(fs.readFileSync('../AdguardHome.yaml', 'utf8'));
|
||||
const { bind_host, bind_port } = doc;
|
||||
return {
|
||||
bind_host,
|
||||
bind_port,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
bind_host: ZERO_HOST,
|
||||
bind_port: DEFAULT_PORT,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const getDevServerConfig = () => {
|
||||
const { bind_host: host, bind_port: port } = importConfig();
|
||||
const { DEV_SERVER_PORT } = process.env;
|
||||
|
||||
const devServerHost = host === ZERO_HOST ? LOCALHOST : host;
|
||||
const devServerPort = 3000 || port + 8000;
|
||||
|
||||
return {
|
||||
host: devServerHost,
|
||||
port: devServerPort
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
importConfig,
|
||||
getDevServerConfig
|
||||
};
|
||||
74
client2/scripts/webpack/webpack.config.base.js
Normal file
74
client2/scripts/webpack/webpack.config.base.js
Normal file
@@ -0,0 +1,74 @@
|
||||
const path = require('path');
|
||||
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const tsconfig = require('../../tsconfig.json');
|
||||
|
||||
const RESOURCES_PATH = path.resolve(__dirname, '../../');
|
||||
const HTML_PATH = path.resolve(RESOURCES_PATH, 'public/index.html');
|
||||
const HTML_INSTALL_PATH = path.resolve(RESOURCES_PATH, 'public/install.html');
|
||||
|
||||
module.exports = {
|
||||
entry: {
|
||||
install: './src/Install.tsx',
|
||||
main: './src/App.tsx'
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.js', '.pcss'],
|
||||
alias: Object.keys(tsconfig.compilerOptions.paths).reduce((aliases, key) => {
|
||||
// Reduce to load aliases from ./tsconfig.json in appropriate for webpack form
|
||||
const paths = tsconfig.compilerOptions.paths[key].map(p => p.replace('/*', ''));
|
||||
aliases[key.replace('/*', '')] = path.resolve(
|
||||
__dirname,
|
||||
'../../',
|
||||
tsconfig.compilerOptions.baseUrl,
|
||||
...paths,
|
||||
);
|
||||
return aliases;
|
||||
}, {}),
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
use: 'ts-loader',
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
{
|
||||
test: /\.(woff|woff2)$/,
|
||||
use: [{
|
||||
loader: 'file-loader',
|
||||
options:{
|
||||
outputPath:'./',
|
||||
}
|
||||
}],
|
||||
},
|
||||
{
|
||||
test:/\.(png|jpe?g|gif)$/,
|
||||
exclude: /(node_modules)/,
|
||||
use:[{
|
||||
loader:'file-loader',
|
||||
options:{
|
||||
outputPath:'./images',
|
||||
}
|
||||
}]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
plugins: [
|
||||
// new AntdDayjsWebpackPlugin()
|
||||
new HtmlWebpackPlugin({
|
||||
inject: true,
|
||||
cache: false,
|
||||
chunks: ['main'],
|
||||
template: HTML_PATH,
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
inject: true,
|
||||
cache: false,
|
||||
chunks: ['install'],
|
||||
filename: 'install.html',
|
||||
template: HTML_INSTALL_PATH,
|
||||
}),
|
||||
],
|
||||
};
|
||||
113
client2/scripts/webpack/webpack.config.dev.js
Normal file
113
client2/scripts/webpack/webpack.config.dev.js
Normal file
@@ -0,0 +1,113 @@
|
||||
const history = require('connect-history-api-fallback');
|
||||
const { merge } = require('webpack-merge');
|
||||
const path = require('path');
|
||||
const proxy = require('http-proxy-middleware');
|
||||
const Webpack = require('webpack');
|
||||
|
||||
const { getDevServerConfig } = require('./helpers');
|
||||
const baseConfig = require('./webpack.config.base');
|
||||
|
||||
const target = getDevServerConfig();
|
||||
|
||||
const options = {
|
||||
target: `http://${target.host}:${target.port}`, // target host
|
||||
changeOrigin: true, // needed for virtual hosted sites
|
||||
};
|
||||
const apiProxy = proxy.createProxyMiddleware(options);
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'development',
|
||||
output: {
|
||||
path: path.resolve(__dirname, '../../build2'),
|
||||
filename: '[name].bundle.js',
|
||||
},
|
||||
optimization: {
|
||||
noEmitOnErrors: true,
|
||||
},
|
||||
devServer: {
|
||||
port: 4000,
|
||||
historyApiFallback: true,
|
||||
before: (app) => {
|
||||
app.use('/control', apiProxy);
|
||||
app.use(history({
|
||||
rewrites: [
|
||||
{
|
||||
from: /\.(png|jpe?g|gif)$/,
|
||||
to: (context) => {
|
||||
const name = context.parsedUrl.pathname.split('/');
|
||||
return `/images/${name[name.length - 1]}`
|
||||
}
|
||||
}, {
|
||||
from: /\.(woff|woff2)$/,
|
||||
to: (context) => {
|
||||
const name = context.parsedUrl.pathname.split('/');
|
||||
return `/${name[name.length - 1]}`
|
||||
}
|
||||
}, {
|
||||
from: /\.(js|css)$/,
|
||||
to: (context) => {
|
||||
const name = context.parsedUrl.pathname.split('/');
|
||||
return `/${name[name.length - 1]}`
|
||||
}
|
||||
}
|
||||
],
|
||||
}));
|
||||
}
|
||||
},
|
||||
devtool: 'eval-source-map',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
enforce: 'pre',
|
||||
test: /\.tsx?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'eslint-loader',
|
||||
options: {
|
||||
configFile: path.resolve(__dirname, '../lint/dev.js'),
|
||||
}
|
||||
},
|
||||
{
|
||||
test: (resource) => {
|
||||
return (
|
||||
resource.indexOf('.pcss')+1
|
||||
|| resource.indexOf('.css')+1
|
||||
|| resource.indexOf('.less')+1
|
||||
) && !(resource.indexOf('.module.')+1);
|
||||
},
|
||||
use: ['style-loader', 'css-loader', 'postcss-loader', {
|
||||
loader: 'less-loader',
|
||||
options: {
|
||||
javascriptEnabled: true,
|
||||
},
|
||||
}],
|
||||
},
|
||||
{
|
||||
test: /\.module\.p?css$/,
|
||||
use: [
|
||||
'style-loader',
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
modules: true,
|
||||
sourceMap: true,
|
||||
importLoaders: 1,
|
||||
modules: {
|
||||
localIdentName: "[name]__[local]___[hash:base64:5]",
|
||||
}
|
||||
},
|
||||
},
|
||||
'postcss-loader',
|
||||
],
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new Webpack.DefinePlugin({
|
||||
DEV: true,
|
||||
'process.env.DEV_SERVER_PORT': JSON.stringify(3000),
|
||||
}),
|
||||
new Webpack.HotModuleReplacementPlugin(),
|
||||
new Webpack.ProgressPlugin(),
|
||||
],
|
||||
});
|
||||
91
client2/scripts/webpack/webpack.config.prod.js
Normal file
91
client2/scripts/webpack/webpack.config.prod.js
Normal file
@@ -0,0 +1,91 @@
|
||||
const path = require('path');
|
||||
const { merge } = require('webpack-merge');
|
||||
const baseConfig = require('./webpack.config.base');
|
||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
||||
const TerserJSPlugin = require('terser-webpack-plugin');
|
||||
const Webpack = require('webpack');
|
||||
const CopyPlugin = require('copy-webpack-plugin');
|
||||
|
||||
module.exports = merge(baseConfig, {
|
||||
mode: 'production',
|
||||
devtool: 'source-map',
|
||||
output: {
|
||||
path: path.resolve(__dirname, '../../../build2/static'),
|
||||
filename: '[name].bundle.[hash:5].js',
|
||||
publicPath: '/'
|
||||
},
|
||||
optimization: {
|
||||
minimizer: [new TerserJSPlugin({terserOptions: {
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
},
|
||||
extractComments: false,
|
||||
}), new OptimizeCSSAssetsPlugin({})],
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
styles: {
|
||||
name: 'styles',
|
||||
test: /\.css$/,
|
||||
chunks: 'all',
|
||||
enforce: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: (resource) => {
|
||||
return (
|
||||
resource.indexOf('.pcss')+1
|
||||
|| resource.indexOf('.css')+1
|
||||
|| resource.indexOf('.less')+1
|
||||
) && !(resource.indexOf('.module.')+1);
|
||||
},
|
||||
use: [{
|
||||
loader: MiniCssExtractPlugin.loader,
|
||||
options: {
|
||||
esModules: true,
|
||||
}
|
||||
}, 'css-loader', 'postcss-loader', {
|
||||
loader: 'less-loader',
|
||||
options: {
|
||||
javascriptEnabled: true,
|
||||
},
|
||||
}],
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
{
|
||||
test: /\.module\.p?css$/,
|
||||
use: [
|
||||
{
|
||||
loader: MiniCssExtractPlugin.loader,
|
||||
options: {
|
||||
esModules: true,
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: 'css-loader',
|
||||
options: {
|
||||
modules: true,
|
||||
sourceMap: true,
|
||||
importLoaders: 1,
|
||||
},
|
||||
},
|
||||
'postcss-loader',
|
||||
],
|
||||
exclude: /node_modules/,
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new Webpack.DefinePlugin({
|
||||
DEV: false,
|
||||
}),
|
||||
new MiniCssExtractPlugin({
|
||||
filename: '[name].[hash:5].css',
|
||||
}),
|
||||
]
|
||||
});
|
||||
Reference in New Issue
Block a user