2024-06-10 18:42:23 +03:00
|
|
|
import { merge } from 'webpack-merge';
|
|
|
|
import yaml from 'js-yaml';
|
|
|
|
import fs from 'fs';
|
|
|
|
import { BASE_URL } from './constants.js';
|
|
|
|
import common from './webpack.common.js';
|
2020-08-13 11:15:45 +03:00
|
|
|
|
|
|
|
const ZERO_HOST = '0.0.0.0';
|
|
|
|
const LOCALHOST = '127.0.0.1';
|
|
|
|
const DEFAULT_PORT = 80;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get document, or throw exception on error
|
|
|
|
* @returns {{bind_host: string, bind_port: number}}
|
|
|
|
*/
|
|
|
|
const importConfig = () => {
|
|
|
|
try {
|
|
|
|
const doc = yaml.safeLoad(fs.readFileSync('../AdguardHome.yaml', 'utf8'));
|
|
|
|
const { bind_host, bind_port } = doc;
|
|
|
|
return {
|
|
|
|
bind_host,
|
|
|
|
bind_port,
|
|
|
|
};
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
return {
|
|
|
|
bind_host: ZERO_HOST,
|
|
|
|
bind_port: DEFAULT_PORT,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const getDevServerConfig = (proxyUrl = BASE_URL) => {
|
|
|
|
const { bind_host: host, bind_port: port } = importConfig();
|
|
|
|
const { DEV_SERVER_PORT } = process.env;
|
|
|
|
|
|
|
|
const devServerHost = host === ZERO_HOST ? LOCALHOST : host;
|
|
|
|
const devServerPort = DEV_SERVER_PORT || port + 8000;
|
|
|
|
|
|
|
|
return {
|
|
|
|
hot: true,
|
2020-09-23 19:47:02 +03:00
|
|
|
open: true,
|
2020-08-13 11:15:45 +03:00
|
|
|
host: devServerHost,
|
|
|
|
port: devServerPort,
|
|
|
|
proxy: {
|
|
|
|
[proxyUrl]: `http://${devServerHost}:${port}`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2018-08-30 17:25:33 +03:00
|
|
|
|
2024-06-10 18:42:23 +03:00
|
|
|
export default merge(common, {
|
2019-07-22 15:32:12 +03:00
|
|
|
devtool: 'eval-source-map',
|
2020-09-23 19:47:02 +03:00
|
|
|
...(process.env.WEBPACK_DEV_SERVER ? { devServer: getDevServerConfig(BASE_URL) } : undefined),
|
2018-08-30 17:25:33 +03:00
|
|
|
});
|