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