2018-08-30 15:25:33 +01:00
|
|
|
const merge = require('webpack-merge');
|
2020-08-13 09:15:45 +01:00
|
|
|
const yaml = require('js-yaml');
|
|
|
|
const fs = require('fs');
|
2018-08-30 15:25:33 +01:00
|
|
|
const common = require('./webpack.common.js');
|
2020-08-13 09:15:45 +01:00
|
|
|
const { BASE_URL } = require('./constants');
|
|
|
|
|
|
|
|
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,
|
|
|
|
host: devServerHost,
|
|
|
|
port: devServerPort,
|
|
|
|
proxy: {
|
|
|
|
[proxyUrl]: `http://${devServerHost}:${port}`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2018-08-30 15:25:33 +01:00
|
|
|
|
|
|
|
module.exports = merge(common, {
|
2019-07-22 13:32:12 +01:00
|
|
|
devtool: 'eval-source-map',
|
2018-08-30 15:25:33 +01:00
|
|
|
module: {
|
2019-07-22 13:32:12 +01:00
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: 'eslint-loader',
|
|
|
|
options: {
|
|
|
|
emitWarning: true,
|
|
|
|
configFile: 'dev.eslintrc',
|
|
|
|
},
|
2018-08-30 15:25:33 +01:00
|
|
|
},
|
2019-07-22 13:32:12 +01:00
|
|
|
],
|
2018-08-30 15:25:33 +01:00
|
|
|
},
|
2020-08-13 09:15:45 +01:00
|
|
|
devServer: process.env.WEBPACK_DEV_SERVER ? getDevServerConfig(BASE_URL) : undefined,
|
2018-08-30 15:25:33 +01:00
|
|
|
});
|