2019-01-31 20:26:41 -05:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const process = require('process');
|
|
|
|
const path = require('path');
|
|
|
|
const postcssPresetEnv = require('postcss-preset-env');
|
2019-05-03 20:14:57 -04:00
|
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
2019-01-31 20:26:41 -05:00
|
|
|
|
2019-07-16 12:22:12 -04:00
|
|
|
const ALWAYS_BABEL = false;
|
|
|
|
|
2019-01-31 20:26:41 -05:00
|
|
|
const { version } = require('./package.json');
|
|
|
|
|
2019-07-16 12:22:12 -04:00
|
|
|
function friendlyErrorFormatter(e) {
|
2019-06-30 22:33:16 -04:00
|
|
|
return `${e.severity}: ${e.content} [TS${e.code}]\n at (${e.file}:${e.line}:${e.character})`;
|
|
|
|
}
|
|
|
|
|
2019-07-19 14:25:25 -04:00
|
|
|
module.exports = env => {
|
|
|
|
let druidUrl = (env || {}).druid_host || process.env.druid_host || 'localhost';
|
2019-05-03 20:14:57 -04:00
|
|
|
if (!druidUrl.startsWith('http')) druidUrl = 'http://' + druidUrl;
|
|
|
|
if (!/:\d+$/.test(druidUrl)) druidUrl += ':8888';
|
|
|
|
|
|
|
|
const proxyTarget = {
|
|
|
|
target: druidUrl,
|
2019-07-19 14:25:25 -04:00
|
|
|
secure: false,
|
2019-05-03 20:14:57 -04:00
|
|
|
};
|
|
|
|
|
2019-07-16 12:22:12 -04:00
|
|
|
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
|
|
|
|
console.log(`Webpack running in ${mode} mode`);
|
2019-01-31 20:26:41 -05:00
|
|
|
return {
|
2019-07-16 12:22:12 -04:00
|
|
|
mode: mode,
|
|
|
|
devtool: 'hidden-source-map',
|
2019-01-31 20:26:41 -05:00
|
|
|
entry: {
|
2019-07-19 14:25:25 -04:00
|
|
|
'web-console': './src/entry.ts',
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, './public'),
|
|
|
|
filename: `[name]-${version}.js`,
|
|
|
|
chunkFilename: `[name]-${version}.js`,
|
2019-07-19 14:25:25 -04:00
|
|
|
publicPath: '/public',
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
|
|
|
target: 'web',
|
|
|
|
resolve: {
|
2019-07-19 14:25:25 -04:00
|
|
|
extensions: ['.tsx', '.ts', '.html', '.js', '.json', '.scss', '.css'],
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
|
|
|
devServer: {
|
|
|
|
publicPath: '/public',
|
|
|
|
index: './index.html',
|
2019-05-03 20:14:57 -04:00
|
|
|
openPage: 'unified-console.html',
|
2019-01-31 20:26:41 -05:00
|
|
|
port: 18081,
|
|
|
|
proxy: {
|
2019-05-03 20:14:57 -04:00
|
|
|
'/status': proxyTarget,
|
2019-05-17 17:01:27 -04:00
|
|
|
'/druid': proxyTarget,
|
2019-07-19 14:25:25 -04:00
|
|
|
'/proxy': proxyTarget,
|
|
|
|
},
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
2019-03-17 12:23:17 -04:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
|
|
|
enforce: 'pre',
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'tslint-loader',
|
|
|
|
options: {
|
|
|
|
configFile: 'tslint.json',
|
|
|
|
emitErrors: true,
|
2019-07-19 14:25:25 -04:00
|
|
|
fix: false, // Set this to true to auto fix errors
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2019-03-17 12:23:17 -04:00
|
|
|
},
|
2019-01-31 20:26:41 -05:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
2019-06-30 22:33:16 -04:00
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
2019-07-19 14:25:25 -04:00
|
|
|
errorFormatter: friendlyErrorFormatter,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
2019-07-16 12:22:12 -04:00
|
|
|
{
|
2019-08-20 23:40:47 -04:00
|
|
|
test: ALWAYS_BABEL || mode === 'production' ? /\.m?js$/ : /^xxx$/,
|
2019-07-16 12:22:12 -04:00
|
|
|
use: {
|
2019-08-20 23:40:47 -04:00
|
|
|
loader: 'babel-loader',
|
|
|
|
},
|
2019-07-16 12:22:12 -04:00
|
|
|
},
|
2019-01-31 20:26:41 -05:00
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
use: [
|
2019-07-19 14:25:25 -04:00
|
|
|
{ loader: 'style-loader' }, // creates style nodes from JS strings
|
|
|
|
{ loader: 'css-loader' }, // translates CSS into CommonJS
|
2019-01-31 20:26:41 -05:00
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
plugins: () => [
|
|
|
|
postcssPresetEnv({
|
2019-07-19 14:25:25 -04:00
|
|
|
browsers: ['> 1%', 'last 3 versions', 'Firefox ESR', 'Opera 12.1'],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
2019-07-19 14:25:25 -04:00
|
|
|
{ loader: 'sass-loader' }, // compiles Sass to CSS, using Node Sass by default
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2019-05-03 20:14:57 -04:00
|
|
|
},
|
2019-07-16 12:22:12 -04:00
|
|
|
performance: {
|
2019-08-20 23:40:47 -04:00
|
|
|
hints: false,
|
2019-07-16 12:22:12 -04:00
|
|
|
},
|
2019-08-20 23:40:47 -04:00
|
|
|
plugins: process.env.BUNDLE_ANALYZER_PLUGIN === 'TRUE' ? [new BundleAnalyzerPlugin()] : [],
|
2019-01-31 20:26:41 -05:00
|
|
|
};
|
|
|
|
};
|