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');
|
2023-03-16 15:44:24 -04:00
|
|
|
const { SassString } = require('sass');
|
2019-05-03 20:14:57 -04:00
|
|
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
2021-04-16 23:15:19 -04:00
|
|
|
const webpack = require('webpack');
|
2019-01-31 20:26:41 -05:00
|
|
|
|
|
|
|
const { version } = require('./package.json');
|
|
|
|
|
2024-07-24 13:50:53 -04:00
|
|
|
const supportedLocales = ['en-US'];
|
|
|
|
|
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';
|
2024-10-03 04:00:46 -04:00
|
|
|
if (!druidUrl.startsWith('http')) {
|
|
|
|
druidUrl = (druidUrl.endsWith(':9088') ? 'https://' : 'http://') + druidUrl;
|
|
|
|
}
|
|
|
|
if (!/:\d+$/.test(druidUrl)) {
|
|
|
|
druidUrl += druidUrl.startsWith('https://') ? ':9088' : ':8888';
|
|
|
|
}
|
2019-05-03 20:14:57 -04:00
|
|
|
|
|
|
|
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';
|
2023-12-05 17:25:07 -05:00
|
|
|
console.log(`Webpack running in ${mode} mode.`);
|
2021-04-16 23:15:19 -04:00
|
|
|
|
|
|
|
const plugins = [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env': JSON.stringify({ NODE_ENV: mode }),
|
2021-04-22 22:33:03 -04:00
|
|
|
'global': {},
|
|
|
|
'NODE_ENV': JSON.stringify(mode),
|
2021-04-16 23:15:19 -04:00
|
|
|
}),
|
2024-07-24 13:50:53 -04:00
|
|
|
|
|
|
|
// Prune date-fns locales to only those that are supported
|
|
|
|
// https://date-fns.org/v2.30.0/docs/webpack
|
|
|
|
new webpack.ContextReplacementPlugin(
|
|
|
|
/^date-fns[/\\]locale$/,
|
|
|
|
new RegExp(`\\.[/\\\\](${supportedLocales.join('|')})[/\\\\]index\\.js$`),
|
|
|
|
),
|
2021-04-16 23:15:19 -04:00
|
|
|
];
|
2019-11-01 00:03:05 -04:00
|
|
|
|
2019-01-31 20:26:41 -05:00
|
|
|
return {
|
2019-07-16 12:22:12 -04:00
|
|
|
mode: mode,
|
2021-04-16 23:15:19 -04:00
|
|
|
devtool: mode === 'production' ? undefined : 'eval-cheap-module-source-map',
|
2019-01-31 20:26:41 -05:00
|
|
|
entry: {
|
2024-07-18 23:47:44 -04:00
|
|
|
'web-console': './src/entry.tsx',
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, './public'),
|
|
|
|
filename: `[name]-${version}.js`,
|
|
|
|
chunkFilename: `[name]-${version}.js`,
|
2020-10-21 01:11:29 -04:00
|
|
|
publicPath: 'public/',
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
|
|
|
target: 'web',
|
|
|
|
resolve: {
|
2022-04-04 13:34:22 -04:00
|
|
|
alias: {
|
|
|
|
// ./node_modules/@blueprintjs/core/src/common/_mixins.scss imports color definitions
|
|
|
|
// from the "lib" folder in @blueprintjs/colors but we need to import it from the "src"
|
|
|
|
// folder. The "src" version includes "!default" in variable definitions, which allows
|
|
|
|
// us to override color variables, but the "lib" version does not.
|
|
|
|
//
|
|
|
|
// Maps './node_modules/@blueprintjs/colors/lib/scss/colors.scss' to './node_modules/@blueprintjs/colors/src/_colors.scss'
|
|
|
|
'@blueprintjs/colors/lib/scss/colors': '@blueprintjs/colors/src/_colors',
|
|
|
|
},
|
2020-10-30 22:02:44 -04:00
|
|
|
extensions: ['.tsx', '.ts', '.js', '.scss', '.css'],
|
2021-04-16 23:15:19 -04:00
|
|
|
fallback: {
|
|
|
|
os: false,
|
|
|
|
},
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
|
|
|
devServer: {
|
2019-09-05 16:56:23 -04:00
|
|
|
host: '0.0.0.0',
|
2019-01-31 20:26:41 -05:00
|
|
|
port: 18081,
|
2023-12-13 19:16:54 -05:00
|
|
|
hot: true,
|
|
|
|
static: {
|
|
|
|
directory: __dirname,
|
|
|
|
},
|
|
|
|
devMiddleware: {
|
|
|
|
publicPath: '/public',
|
|
|
|
},
|
|
|
|
open: 'unified-console.html',
|
2019-01-31 20:26:41 -05:00
|
|
|
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: [
|
|
|
|
{
|
|
|
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
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: {
|
2021-04-16 23:15:19 -04:00
|
|
|
postcssOptions: {
|
|
|
|
plugins: {
|
|
|
|
'postcss-preset-env': {
|
|
|
|
autoprefixer: { grid: 'no-autoplace' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-19 14:25:25 -04:00
|
|
|
},
|
2019-01-31 20:26:41 -05:00
|
|
|
},
|
2023-03-16 15:44:24 -04:00
|
|
|
{
|
|
|
|
// compiles Sass to CSS, using Dart Sass by default
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
sassOptions: {
|
|
|
|
functions: {
|
|
|
|
// Blueprint's usage of SCSS is dependent on 'node-sass', but we use Dart
|
|
|
|
// Sass for broader compatibility across CPU architectures. Blueprint's build
|
|
|
|
// process substitutes these 'svg-icon' functions with actual icons but we don't
|
|
|
|
// have access to them at this point. None of the components that use svg icons
|
|
|
|
// via CSS are themselves being used by the web console, so we can safely omit the icons.
|
|
|
|
//
|
2024-07-24 13:50:53 -04:00
|
|
|
// TODO: Re-evaluate after upgrading to Blueprint v6
|
2023-03-16 15:44:24 -04:00
|
|
|
'svg-icon($_icon, $_path)': () => new SassString('transparent'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-19 14:25:25 -04:00
|
|
|
],
|
|
|
|
},
|
2020-10-21 01:11:29 -04:00
|
|
|
{
|
|
|
|
test: /\.(woff|woff2|ttf|eot)$/,
|
|
|
|
use: {
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
2021-04-16 23:15:19 -04:00
|
|
|
name: '[name].[ext]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-19 14:25:25 -04:00
|
|
|
],
|
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
|
|
|
},
|
2021-04-16 23:15:19 -04:00
|
|
|
plugins:
|
|
|
|
process.env.BUNDLE_ANALYZER_PLUGIN === 'TRUE'
|
|
|
|
? [...plugins, new BundleAnalyzerPlugin()]
|
|
|
|
: plugins,
|
2019-01-31 20:26:41 -05:00
|
|
|
};
|
|
|
|
};
|