2020-03-17 18:37:07 -04:00
|
|
|
/* eslint-disable no-console */
|
2019-01-15 18:53:27 -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.
|
|
|
|
*/
|
2020-03-17 18:37:07 -04:00
|
|
|
const fs = require('fs');
|
2016-07-14 22:50:47 -04:00
|
|
|
const path = require('path');
|
2018-09-04 13:39:05 -04:00
|
|
|
const webpack = require('webpack');
|
2020-03-26 19:55:22 -04:00
|
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
2020-02-09 20:53:56 -05:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
2021-03-04 12:58:16 -05:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
[webpack 4] third time's the charm ;) (#5370)
* [perf] add webpack 4 + SplitChunks + lazy load visualizations (#5240)
* [webpack] setup lazy loading for all visualizations
* [lazy-load] push renderVis function to <Chart /> state
* no mapbox token
* [lazy loading] use native webpack import func to fix chunk names, add babel-plugin-syntax-dynamic-import, fix rebase bug.
* fix geojson import, undefined t, and fix async css bug
* [lazy load] actually add babel-plugin-syntax-dynamic-import
* [webpack] working dev version of webpack v4
* [webpack 4] fix url issues, use mini-css-extract-plugin and webpack-assets-manifest plugins
* [webpack 4] use splitchunks for all files, update templates to multi-file entrypoints
* [webpack 4] multiple theme entry files for markup vis css, don't uglify mapbox
* [webpack 4] lint python manifest changes, update yarn lock.
* [webpack 4] fix tests with babel-plugin-dynamic-import-node
* [webpack 4] only use 'dynamic-import-node' plugin in tests, update <Chart /> vis promise when vis type changes
* [webpack 4] clean up package.json and yarn.lock after rebase
* [webpack 4] lint?
* [webpack 4] lint for real
* [webpack 4][istanbul] ignore visualizations/index.js
* [webpack 4] fix rebase bug, update dashboard/deprecated/chart/Chart.jsx to use vis promises.
* [webpack 4] lint and test
* [webpack 4] yarn.lock
2018-07-17 16:55:03 -04:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2021-09-22 07:24:54 -04:00
|
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
2018-09-27 15:49:05 -04:00
|
|
|
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
|
2021-09-22 07:24:54 -04:00
|
|
|
const {
|
|
|
|
WebpackManifestPlugin,
|
|
|
|
getCompilerHooks,
|
|
|
|
} = require('webpack-manifest-plugin');
|
2018-10-24 01:33:51 -04:00
|
|
|
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
2020-03-17 18:37:07 -04:00
|
|
|
const parsedArgs = require('yargs').argv;
|
2020-03-26 19:55:22 -04:00
|
|
|
const getProxyConfig = require('./webpack.proxy-config');
|
2021-09-22 07:24:54 -04:00
|
|
|
const packageConfig = require('./package');
|
2016-03-18 02:44:58 -04:00
|
|
|
|
2016-07-27 19:57:05 -04:00
|
|
|
// input dir
|
|
|
|
const APP_DIR = path.resolve(__dirname, './');
|
|
|
|
// output dir
|
2020-02-09 20:53:56 -05:00
|
|
|
const BUILD_DIR = path.resolve(__dirname, '../superset/static/assets');
|
2021-04-27 15:03:35 -04:00
|
|
|
const ROOT_DIR = path.resolve(__dirname, '..');
|
2016-07-14 22:50:47 -04:00
|
|
|
|
2018-09-04 13:39:05 -04:00
|
|
|
const {
|
|
|
|
mode = 'development',
|
|
|
|
devserverPort = 9000,
|
2018-09-27 15:49:05 -04:00
|
|
|
measure = false,
|
|
|
|
analyzeBundle = false,
|
2020-09-10 18:11:21 -04:00
|
|
|
analyzerPort = 8888,
|
|
|
|
nameChunks = false,
|
2018-09-04 13:39:05 -04:00
|
|
|
} = parsedArgs;
|
|
|
|
const isDevMode = mode !== 'production';
|
2020-11-11 16:14:45 -05:00
|
|
|
const isDevServer = process.argv[1].includes('webpack-dev-server');
|
2021-06-14 20:55:58 -04:00
|
|
|
const ASSET_BASE_URL = process.env.ASSET_BASE_URL || '';
|
2018-09-04 13:39:05 -04:00
|
|
|
|
2020-03-17 18:37:07 -04:00
|
|
|
const output = {
|
|
|
|
path: BUILD_DIR,
|
2021-06-14 20:55:58 -04:00
|
|
|
publicPath: `${ASSET_BASE_URL}/static/assets/`,
|
2020-03-17 18:37:07 -04:00
|
|
|
};
|
|
|
|
if (isDevMode) {
|
2021-09-22 07:24:54 -04:00
|
|
|
output.filename = '[name].[contenthash:8].entry.js';
|
|
|
|
output.chunkFilename = '[name].[contenthash:8].chunk.js';
|
2020-09-15 17:12:06 -04:00
|
|
|
} else if (nameChunks) {
|
2021-06-23 12:41:19 -04:00
|
|
|
output.filename = '[name].[chunkhash].entry.js';
|
|
|
|
output.chunkFilename = '[name].[chunkhash].chunk.js';
|
2020-09-15 17:12:06 -04:00
|
|
|
} else {
|
2021-06-23 12:41:19 -04:00
|
|
|
output.filename = '[name].[chunkhash].entry.js';
|
|
|
|
output.chunkFilename = '[chunkhash].chunk.js';
|
2020-03-17 18:37:07 -04:00
|
|
|
}
|
|
|
|
|
2021-09-22 07:24:54 -04:00
|
|
|
if (!isDevMode) {
|
|
|
|
output.clean = true;
|
|
|
|
}
|
|
|
|
|
2018-09-04 13:39:05 -04:00
|
|
|
const plugins = [
|
2021-09-22 07:24:54 -04:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
process: 'process/browser',
|
|
|
|
}),
|
|
|
|
|
2018-09-04 13:39:05 -04:00
|
|
|
// creates a manifest.json mapping of name to hashed output used in template files
|
2021-09-22 07:24:54 -04:00
|
|
|
new WebpackManifestPlugin({
|
2020-03-26 19:55:22 -04:00
|
|
|
publicPath: output.publicPath,
|
|
|
|
seed: { app: 'superset' },
|
2018-09-04 13:39:05 -04:00
|
|
|
// This enables us to include all relevant files for an entry
|
2020-03-26 19:55:22 -04:00
|
|
|
generate: (seed, files, entrypoints) => {
|
|
|
|
// Each entrypoint's chunk files in the format of
|
|
|
|
// {
|
|
|
|
// entry: {
|
|
|
|
// css: [],
|
|
|
|
// js: []
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
const entryFiles = {};
|
2020-09-18 12:05:57 -04:00
|
|
|
Object.entries(entrypoints).forEach(([entry, chunks]) => {
|
2020-03-26 19:55:22 -04:00
|
|
|
entryFiles[entry] = {
|
|
|
|
css: chunks
|
|
|
|
.filter(x => x.endsWith('.css'))
|
|
|
|
.map(x => path.join(output.publicPath, x)),
|
|
|
|
js: chunks
|
|
|
|
.filter(x => x.endsWith('.js'))
|
|
|
|
.map(x => path.join(output.publicPath, x)),
|
|
|
|
};
|
2020-09-18 12:05:57 -04:00
|
|
|
});
|
|
|
|
|
2020-03-26 19:55:22 -04:00
|
|
|
return {
|
|
|
|
...seed,
|
|
|
|
entrypoints: entryFiles,
|
|
|
|
};
|
|
|
|
},
|
2020-11-11 16:14:45 -05:00
|
|
|
// Also write maniafest.json to disk when running `npm run dev`.
|
|
|
|
// This is required for Flask to work.
|
|
|
|
writeToFileEmit: isDevMode && !isDevServer,
|
2020-02-09 20:53:56 -05:00
|
|
|
}),
|
2018-09-11 13:35:52 -04:00
|
|
|
|
|
|
|
// expose mode variable to other modules
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.WEBPACK_MODE': JSON.stringify(mode),
|
|
|
|
}),
|
2018-10-24 01:33:51 -04:00
|
|
|
|
|
|
|
// runs type checking on a separate process to speed up the build
|
|
|
|
new ForkTsCheckerWebpackPlugin({
|
2021-09-22 07:24:54 -04:00
|
|
|
eslint: {
|
|
|
|
files: './src/**/*.{ts,tsx,js,jsx}',
|
|
|
|
memoryLimit: 4096,
|
|
|
|
},
|
2018-10-24 01:33:51 -04:00
|
|
|
}),
|
2020-02-09 20:53:56 -05:00
|
|
|
|
2020-08-17 18:27:01 -04:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
2020-03-08 13:03:58 -04:00
|
|
|
'package.json',
|
2021-09-22 09:28:51 -04:00
|
|
|
{ from: 'src/assets/images', to: 'images' },
|
2021-09-30 08:28:38 -04:00
|
|
|
{ from: 'src/assets/stylesheets', to: 'stylesheets' },
|
2020-03-08 13:03:58 -04:00
|
|
|
],
|
2020-08-17 18:27:01 -04:00
|
|
|
}),
|
2021-03-04 12:58:16 -05:00
|
|
|
|
|
|
|
// static pages
|
|
|
|
new HtmlWebpackPlugin({
|
2021-04-20 11:47:24 -04:00
|
|
|
template: './src/assets/staticPages/404.html',
|
2021-03-04 12:58:16 -05:00
|
|
|
inject: true,
|
|
|
|
chunks: [],
|
|
|
|
filename: '404.html',
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
2021-04-20 11:47:24 -04:00
|
|
|
template: './src/assets/staticPages/500.html',
|
2021-03-04 12:58:16 -05:00
|
|
|
inject: true,
|
|
|
|
chunks: [],
|
|
|
|
filename: '500.html',
|
|
|
|
}),
|
2018-09-04 13:39:05 -04:00
|
|
|
];
|
2020-11-11 16:14:45 -05:00
|
|
|
|
2020-05-12 19:09:18 -04:00
|
|
|
if (!process.env.CI) {
|
|
|
|
plugins.push(new webpack.ProgressPlugin());
|
|
|
|
}
|
2020-11-11 16:14:45 -05:00
|
|
|
|
2020-03-19 17:57:39 -04:00
|
|
|
if (!isDevMode) {
|
2018-09-04 13:39:05 -04:00
|
|
|
// text loading (webpack 4+)
|
2019-11-27 17:02:48 -05:00
|
|
|
plugins.push(
|
|
|
|
new MiniCssExtractPlugin({
|
2021-06-23 12:41:19 -04:00
|
|
|
filename: '[name].[chunkhash].entry.css',
|
|
|
|
chunkFilename: '[name].[chunkhash].chunk.css',
|
2019-11-27 17:02:48 -05:00
|
|
|
}),
|
|
|
|
);
|
2018-09-04 13:39:05 -04:00
|
|
|
}
|
|
|
|
|
2020-05-24 22:50:08 -04:00
|
|
|
const PREAMBLE = [path.join(APP_DIR, '/src/preamble.ts')];
|
2020-03-19 17:57:39 -04:00
|
|
|
if (isDevMode) {
|
2020-05-24 22:50:08 -04:00
|
|
|
// A Superset webpage normally includes two JS bundles in dev, `theme.ts` and
|
2020-03-19 17:57:39 -04:00
|
|
|
// the main entrypoint. Only the main entry should have the dev server client,
|
|
|
|
// otherwise the websocket client will initialize twice, creating two sockets.
|
|
|
|
// Ref: https://github.com/gaearon/react-hot-loader/issues/141
|
|
|
|
PREAMBLE.unshift(
|
|
|
|
`webpack-dev-server/client?http://localhost:${devserverPort}`,
|
|
|
|
);
|
|
|
|
}
|
2018-10-30 17:51:44 -04:00
|
|
|
|
|
|
|
function addPreamble(entry) {
|
|
|
|
return PREAMBLE.concat([path.join(APP_DIR, entry)]);
|
|
|
|
}
|
|
|
|
|
2020-03-19 17:57:39 -04:00
|
|
|
const babelLoader = {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: true,
|
2020-03-26 19:55:22 -04:00
|
|
|
// disable gzip compression for cache files
|
|
|
|
// faster when there are millions of small files
|
2020-03-19 17:57:39 -04:00
|
|
|
cacheCompression: false,
|
2020-04-13 16:39:55 -04:00
|
|
|
plugins: ['emotion'],
|
2020-04-30 00:54:07 -04:00
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'@emotion/babel-preset-css-prop',
|
|
|
|
{
|
2021-01-10 20:26:35 -05:00
|
|
|
autoLabel: 'dev-only',
|
2020-04-30 00:54:07 -04:00
|
|
|
labelFormat: '[local]',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
2020-03-19 17:57:39 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-07-14 22:50:47 -04:00
|
|
|
const config = {
|
2016-03-18 02:44:58 -04:00
|
|
|
entry: {
|
2018-10-30 17:51:44 -04:00
|
|
|
preamble: PREAMBLE,
|
2021-05-04 11:51:17 -04:00
|
|
|
theme: path.join(APP_DIR, '/src/theme.ts'),
|
|
|
|
menu: addPreamble('src/views/menu.tsx'),
|
|
|
|
spa: addPreamble('/src/views/index.tsx'),
|
2020-06-22 11:14:27 -04:00
|
|
|
addSlice: addPreamble('/src/addSlice/index.tsx'),
|
2018-10-30 17:51:44 -04:00
|
|
|
explore: addPreamble('/src/explore/index.jsx'),
|
2020-07-14 19:39:56 -04:00
|
|
|
sqllab: addPreamble('/src/SqlLab/index.tsx'),
|
2020-07-14 19:39:37 -04:00
|
|
|
profile: addPreamble('/src/profile/index.tsx'),
|
2019-05-17 20:31:02 -04:00
|
|
|
showSavedQuery: [path.join(APP_DIR, '/src/showSavedQuery/index.jsx')],
|
2016-03-18 02:44:58 -04:00
|
|
|
},
|
2018-09-04 13:39:05 -04:00
|
|
|
output,
|
2020-03-19 17:57:39 -04:00
|
|
|
stats: 'minimal',
|
|
|
|
performance: {
|
|
|
|
assetFilter(assetFilename) {
|
|
|
|
// don't throw size limit warning on geojson and font files
|
|
|
|
return !/\.(map|geojson|woff2)$/.test(assetFilename);
|
|
|
|
},
|
|
|
|
},
|
[webpack 4] third time's the charm ;) (#5370)
* [perf] add webpack 4 + SplitChunks + lazy load visualizations (#5240)
* [webpack] setup lazy loading for all visualizations
* [lazy-load] push renderVis function to <Chart /> state
* no mapbox token
* [lazy loading] use native webpack import func to fix chunk names, add babel-plugin-syntax-dynamic-import, fix rebase bug.
* fix geojson import, undefined t, and fix async css bug
* [lazy load] actually add babel-plugin-syntax-dynamic-import
* [webpack] working dev version of webpack v4
* [webpack 4] fix url issues, use mini-css-extract-plugin and webpack-assets-manifest plugins
* [webpack 4] use splitchunks for all files, update templates to multi-file entrypoints
* [webpack 4] multiple theme entry files for markup vis css, don't uglify mapbox
* [webpack 4] lint python manifest changes, update yarn lock.
* [webpack 4] fix tests with babel-plugin-dynamic-import-node
* [webpack 4] only use 'dynamic-import-node' plugin in tests, update <Chart /> vis promise when vis type changes
* [webpack 4] clean up package.json and yarn.lock after rebase
* [webpack 4] lint?
* [webpack 4] lint for real
* [webpack 4][istanbul] ignore visualizations/index.js
* [webpack 4] fix rebase bug, update dashboard/deprecated/chart/Chart.jsx to use vis promises.
* [webpack 4] lint and test
* [webpack 4] yarn.lock
2018-07-17 16:55:03 -04:00
|
|
|
optimization: {
|
2020-06-29 00:37:04 -04:00
|
|
|
sideEffects: true,
|
[webpack 4] third time's the charm ;) (#5370)
* [perf] add webpack 4 + SplitChunks + lazy load visualizations (#5240)
* [webpack] setup lazy loading for all visualizations
* [lazy-load] push renderVis function to <Chart /> state
* no mapbox token
* [lazy loading] use native webpack import func to fix chunk names, add babel-plugin-syntax-dynamic-import, fix rebase bug.
* fix geojson import, undefined t, and fix async css bug
* [lazy load] actually add babel-plugin-syntax-dynamic-import
* [webpack] working dev version of webpack v4
* [webpack 4] fix url issues, use mini-css-extract-plugin and webpack-assets-manifest plugins
* [webpack 4] use splitchunks for all files, update templates to multi-file entrypoints
* [webpack 4] multiple theme entry files for markup vis css, don't uglify mapbox
* [webpack 4] lint python manifest changes, update yarn lock.
* [webpack 4] fix tests with babel-plugin-dynamic-import-node
* [webpack 4] only use 'dynamic-import-node' plugin in tests, update <Chart /> vis promise when vis type changes
* [webpack 4] clean up package.json and yarn.lock after rebase
* [webpack 4] lint?
* [webpack 4] lint for real
* [webpack 4][istanbul] ignore visualizations/index.js
* [webpack 4] fix rebase bug, update dashboard/deprecated/chart/Chart.jsx to use vis promises.
* [webpack 4] lint and test
* [webpack 4] yarn.lock
2018-07-17 16:55:03 -04:00
|
|
|
splitChunks: {
|
|
|
|
chunks: 'all',
|
2020-09-15 17:12:06 -04:00
|
|
|
// increase minSize for devMode to 1000kb because of sourcemap
|
|
|
|
minSize: isDevMode ? 1000000 : 20000,
|
2020-09-10 18:11:21 -04:00
|
|
|
name: nameChunks,
|
[webpack 4] third time's the charm ;) (#5370)
* [perf] add webpack 4 + SplitChunks + lazy load visualizations (#5240)
* [webpack] setup lazy loading for all visualizations
* [lazy-load] push renderVis function to <Chart /> state
* no mapbox token
* [lazy loading] use native webpack import func to fix chunk names, add babel-plugin-syntax-dynamic-import, fix rebase bug.
* fix geojson import, undefined t, and fix async css bug
* [lazy load] actually add babel-plugin-syntax-dynamic-import
* [webpack] working dev version of webpack v4
* [webpack 4] fix url issues, use mini-css-extract-plugin and webpack-assets-manifest plugins
* [webpack 4] use splitchunks for all files, update templates to multi-file entrypoints
* [webpack 4] multiple theme entry files for markup vis css, don't uglify mapbox
* [webpack 4] lint python manifest changes, update yarn lock.
* [webpack 4] fix tests with babel-plugin-dynamic-import-node
* [webpack 4] only use 'dynamic-import-node' plugin in tests, update <Chart /> vis promise when vis type changes
* [webpack 4] clean up package.json and yarn.lock after rebase
* [webpack 4] lint?
* [webpack 4] lint for real
* [webpack 4][istanbul] ignore visualizations/index.js
* [webpack 4] fix rebase bug, update dashboard/deprecated/chart/Chart.jsx to use vis promises.
* [webpack 4] lint and test
* [webpack 4] yarn.lock
2018-07-17 16:55:03 -04:00
|
|
|
automaticNameDelimiter: '-',
|
2018-09-27 15:49:05 -04:00
|
|
|
minChunks: 2,
|
|
|
|
cacheGroups: {
|
2020-09-10 18:11:21 -04:00
|
|
|
automaticNamePrefix: 'chunk',
|
|
|
|
// basic stable dependencies
|
|
|
|
vendors: {
|
|
|
|
priority: 50,
|
|
|
|
name: 'vendors',
|
|
|
|
test: new RegExp(
|
|
|
|
`/node_modules/(${[
|
|
|
|
'abortcontroller-polyfill',
|
|
|
|
'react',
|
|
|
|
'react-dom',
|
|
|
|
'prop-types',
|
2020-09-15 17:12:06 -04:00
|
|
|
'react-prop-types',
|
|
|
|
'prop-types-extra',
|
2020-09-10 18:11:21 -04:00
|
|
|
'redux',
|
|
|
|
'react-redux',
|
|
|
|
'react-hot-loader',
|
|
|
|
'react-select',
|
|
|
|
'react-sortable-hoc',
|
|
|
|
'react-virtualized',
|
|
|
|
'react-table',
|
2020-09-15 17:12:06 -04:00
|
|
|
'react-ace',
|
2020-09-10 18:11:21 -04:00
|
|
|
'@hot-loader.*',
|
|
|
|
'webpack.*',
|
|
|
|
'@?babel.*',
|
|
|
|
'lodash.*',
|
|
|
|
'antd',
|
|
|
|
'@ant-design.*',
|
|
|
|
'.*bootstrap',
|
|
|
|
'moment',
|
|
|
|
'jquery',
|
|
|
|
'core-js.*',
|
|
|
|
'@emotion.*',
|
2020-09-15 17:12:06 -04:00
|
|
|
'd3',
|
|
|
|
'd3-(array|color|scale|interpolate|format|selection|collection|time|time-format)',
|
2020-09-10 18:11:21 -04:00
|
|
|
].join('|')})/`,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
// viz thumbnails are used in `addSlice` and `explore` page
|
|
|
|
thumbnail: {
|
|
|
|
name: 'thumbnail',
|
2021-07-12 13:59:10 -04:00
|
|
|
test: /thumbnail(Large)?\.(png|jpg)/i,
|
2020-09-10 18:11:21 -04:00
|
|
|
priority: 20,
|
|
|
|
enforce: true,
|
2018-09-27 15:49:05 -04:00
|
|
|
},
|
|
|
|
},
|
2018-06-20 15:07:42 -04:00
|
|
|
},
|
2021-10-05 14:13:33 -04:00
|
|
|
usedExports: 'global',
|
2021-10-25 17:47:09 -04:00
|
|
|
minimizer: [new CssMinimizerPlugin(), '...'],
|
[webpack 4] third time's the charm ;) (#5370)
* [perf] add webpack 4 + SplitChunks + lazy load visualizations (#5240)
* [webpack] setup lazy loading for all visualizations
* [lazy-load] push renderVis function to <Chart /> state
* no mapbox token
* [lazy loading] use native webpack import func to fix chunk names, add babel-plugin-syntax-dynamic-import, fix rebase bug.
* fix geojson import, undefined t, and fix async css bug
* [lazy load] actually add babel-plugin-syntax-dynamic-import
* [webpack] working dev version of webpack v4
* [webpack 4] fix url issues, use mini-css-extract-plugin and webpack-assets-manifest plugins
* [webpack 4] use splitchunks for all files, update templates to multi-file entrypoints
* [webpack 4] multiple theme entry files for markup vis css, don't uglify mapbox
* [webpack 4] lint python manifest changes, update yarn lock.
* [webpack 4] fix tests with babel-plugin-dynamic-import-node
* [webpack 4] only use 'dynamic-import-node' plugin in tests, update <Chart /> vis promise when vis type changes
* [webpack 4] clean up package.json and yarn.lock after rebase
* [webpack 4] lint?
* [webpack 4] lint for real
* [webpack 4][istanbul] ignore visualizations/index.js
* [webpack 4] fix rebase bug, update dashboard/deprecated/chart/Chart.jsx to use vis promises.
* [webpack 4] lint and test
* [webpack 4] yarn.lock
2018-07-17 16:55:03 -04:00
|
|
|
},
|
|
|
|
resolve: {
|
2021-04-27 15:03:35 -04:00
|
|
|
modules: [APP_DIR, 'node_modules', ROOT_DIR],
|
2018-10-24 01:33:51 -04:00
|
|
|
alias: {
|
2020-03-19 17:57:39 -04:00
|
|
|
'react-dom': '@hot-loader/react-dom',
|
2021-01-14 13:20:13 -05:00
|
|
|
// Force using absolute import path of some packages in the root node_modules,
|
|
|
|
// as they can be dependencies of other packages via `npm link`.
|
2020-10-13 19:54:06 -04:00
|
|
|
'@superset-ui/core': path.resolve(
|
|
|
|
APP_DIR,
|
|
|
|
'./node_modules/@superset-ui/core',
|
|
|
|
),
|
|
|
|
'@superset-ui/chart-controls': path.resolve(
|
|
|
|
APP_DIR,
|
|
|
|
'./node_modules/@superset-ui/chart-controls',
|
|
|
|
),
|
2021-10-04 12:47:07 -04:00
|
|
|
react: path.resolve('./node_modules/react'),
|
2018-10-24 01:33:51 -04:00
|
|
|
},
|
2021-04-27 15:03:35 -04:00
|
|
|
extensions: ['.ts', '.tsx', '.js', '.jsx', '.yml'],
|
2021-09-22 07:24:54 -04:00
|
|
|
fallback: {
|
|
|
|
fs: false,
|
|
|
|
vm: false,
|
|
|
|
path: false,
|
|
|
|
},
|
Map visualization (#650)
* simple mapbox viz
use react-map-gl
superclustering of long/lat points
Added hook for map style, huge performance boost from bounding box fix, added count text on clusters
variable gradient size based on metric count
Ability to aggregate over any point property
This needed a change in the supercluster npm module, a PR was placed here:
https://github.com/mapbox/supercluster/pull/12
Aggregator function option in explore, tweaked visual defaults
better radius size management
clustering radius, point metric/unit options
scale cluster labels that don't fit, non-numeric labels for points
Minor fixes, label field affects points, text changes
serve mapbox apikey for slice
global opacity, viewport saves (hacky), bug in point labels
fixing mapbox-gl dependency
mapbox_api_key in config
expose row_limit, fix minor bugs
Add renderWhileDragging flag, groupby. Only show numerical columns for point radius
Implicitly group by lng/lat columns and error when label doesn't match groupby
'Fix' radius in miles problem, still some jankiness
derived fields cannot be typed as of now -> reverting numerical number change
better grouping error checking, expose count(*) for labelling
Custom colour for clusters/points + smart text colouring
Fixed bad positioning and overflow in explore view + small bugs + added thumbnail
* landscaping & eslint & use izip
* landscapin'
* address js code review
2016-06-24 17:16:51 -04:00
|
|
|
},
|
2018-10-24 01:33:51 -04:00
|
|
|
context: APP_DIR, // to automatically find tsconfig.json
|
2016-03-18 02:44:58 -04:00
|
|
|
module: {
|
2018-06-11 00:43:37 -04:00
|
|
|
rules: [
|
2020-06-30 14:38:36 -04:00
|
|
|
{
|
|
|
|
test: /datatables\.net.*/,
|
2021-09-22 07:24:54 -04:00
|
|
|
loader: 'imports-loader',
|
|
|
|
options: {
|
|
|
|
additionalCode: 'var define = false;',
|
|
|
|
},
|
2020-06-30 14:38:36 -04:00
|
|
|
},
|
2018-10-24 01:33:51 -04:00
|
|
|
{
|
|
|
|
test: /\.tsx?$/,
|
2020-08-19 15:54:26 -04:00
|
|
|
exclude: [/\.test.tsx?$/],
|
2018-10-24 01:33:51 -04:00
|
|
|
use: [
|
2020-03-19 17:57:39 -04:00
|
|
|
'thread-loader',
|
|
|
|
babelLoader,
|
2018-10-24 01:33:51 -04:00
|
|
|
{
|
|
|
|
loader: 'ts-loader',
|
|
|
|
options: {
|
|
|
|
// transpile only in happyPack mode
|
|
|
|
// type checking is done via fork-ts-checker-webpack-plugin
|
|
|
|
happyPackMode: true,
|
2020-03-19 17:57:39 -04:00
|
|
|
transpileOnly: true,
|
2020-03-30 12:31:46 -04:00
|
|
|
// must override compiler options here, even though we have set
|
|
|
|
// the same options in `tsconfig.json`, because they may still
|
|
|
|
// be overriden by `tsconfig.json` in node_modules subdirectories.
|
|
|
|
compilerOptions: {
|
|
|
|
esModuleInterop: false,
|
|
|
|
importHelpers: false,
|
|
|
|
module: 'esnext',
|
|
|
|
target: 'esnext',
|
|
|
|
},
|
2018-10-24 01:33:51 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2016-03-18 02:44:58 -04:00
|
|
|
{
|
2016-07-14 22:50:47 -04:00
|
|
|
test: /\.jsx?$/,
|
2020-08-19 15:54:26 -04:00
|
|
|
// include source code for plugins, but exclude node_modules and test files within them
|
|
|
|
exclude: [/superset-ui.*\/node_modules\//, /\.test.jsx?$/],
|
2020-07-22 13:21:25 -04:00
|
|
|
include: [
|
|
|
|
new RegExp(`${APP_DIR}/src`),
|
|
|
|
/superset-ui.*\/src/,
|
|
|
|
new RegExp(`${APP_DIR}/.storybook`),
|
2021-08-02 13:57:29 -04:00
|
|
|
/@encodable/,
|
2020-07-22 13:21:25 -04:00
|
|
|
],
|
2020-03-19 17:57:39 -04:00
|
|
|
use: [babelLoader],
|
2019-02-14 20:57:34 -05:00
|
|
|
},
|
2016-03-18 02:44:58 -04:00
|
|
|
{
|
|
|
|
test: /\.css$/,
|
2020-03-19 17:57:39 -04:00
|
|
|
include: [APP_DIR, /superset-ui.+\/src/],
|
2018-09-04 13:39:05 -04:00
|
|
|
use: [
|
2018-09-05 12:17:18 -04:00
|
|
|
isDevMode ? 'style-loader' : MiniCssExtractPlugin.loader,
|
2019-11-26 13:09:39 -05:00
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
2019-12-02 20:20:43 -05:00
|
|
|
sourceMap: isDevMode,
|
2019-11-26 13:09:39 -05:00
|
|
|
},
|
|
|
|
},
|
2018-09-04 13:39:05 -04:00
|
|
|
],
|
2017-08-09 12:52:43 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.less$/,
|
|
|
|
include: APP_DIR,
|
[webpack 4] third time's the charm ;) (#5370)
* [perf] add webpack 4 + SplitChunks + lazy load visualizations (#5240)
* [webpack] setup lazy loading for all visualizations
* [lazy-load] push renderVis function to <Chart /> state
* no mapbox token
* [lazy loading] use native webpack import func to fix chunk names, add babel-plugin-syntax-dynamic-import, fix rebase bug.
* fix geojson import, undefined t, and fix async css bug
* [lazy load] actually add babel-plugin-syntax-dynamic-import
* [webpack] working dev version of webpack v4
* [webpack 4] fix url issues, use mini-css-extract-plugin and webpack-assets-manifest plugins
* [webpack 4] use splitchunks for all files, update templates to multi-file entrypoints
* [webpack 4] multiple theme entry files for markup vis css, don't uglify mapbox
* [webpack 4] lint python manifest changes, update yarn lock.
* [webpack 4] fix tests with babel-plugin-dynamic-import-node
* [webpack 4] only use 'dynamic-import-node' plugin in tests, update <Chart /> vis promise when vis type changes
* [webpack 4] clean up package.json and yarn.lock after rebase
* [webpack 4] lint?
* [webpack 4] lint for real
* [webpack 4][istanbul] ignore visualizations/index.js
* [webpack 4] fix rebase bug, update dashboard/deprecated/chart/Chart.jsx to use vis promises.
* [webpack 4] lint and test
* [webpack 4] yarn.lock
2018-07-17 16:55:03 -04:00
|
|
|
use: [
|
2018-09-05 12:17:18 -04:00
|
|
|
isDevMode ? 'style-loader' : MiniCssExtractPlugin.loader,
|
2019-11-26 13:09:39 -05:00
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
2019-12-02 20:20:43 -05:00
|
|
|
sourceMap: isDevMode,
|
2019-11-26 13:09:39 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'less-loader',
|
|
|
|
options: {
|
2019-12-02 20:20:43 -05:00
|
|
|
sourceMap: isDevMode,
|
2020-08-05 16:50:30 -04:00
|
|
|
javascriptEnabled: true,
|
2019-11-26 13:09:39 -05:00
|
|
|
},
|
|
|
|
},
|
[webpack 4] third time's the charm ;) (#5370)
* [perf] add webpack 4 + SplitChunks + lazy load visualizations (#5240)
* [webpack] setup lazy loading for all visualizations
* [lazy-load] push renderVis function to <Chart /> state
* no mapbox token
* [lazy loading] use native webpack import func to fix chunk names, add babel-plugin-syntax-dynamic-import, fix rebase bug.
* fix geojson import, undefined t, and fix async css bug
* [lazy load] actually add babel-plugin-syntax-dynamic-import
* [webpack] working dev version of webpack v4
* [webpack 4] fix url issues, use mini-css-extract-plugin and webpack-assets-manifest plugins
* [webpack 4] use splitchunks for all files, update templates to multi-file entrypoints
* [webpack 4] multiple theme entry files for markup vis css, don't uglify mapbox
* [webpack 4] lint python manifest changes, update yarn lock.
* [webpack 4] fix tests with babel-plugin-dynamic-import-node
* [webpack 4] only use 'dynamic-import-node' plugin in tests, update <Chart /> vis promise when vis type changes
* [webpack 4] clean up package.json and yarn.lock after rebase
* [webpack 4] lint?
* [webpack 4] lint for real
* [webpack 4][istanbul] ignore visualizations/index.js
* [webpack 4] fix rebase bug, update dashboard/deprecated/chart/Chart.jsx to use vis promises.
* [webpack 4] lint and test
* [webpack 4] yarn.lock
2018-07-17 16:55:03 -04:00
|
|
|
],
|
2016-03-18 02:44:58 -04:00
|
|
|
},
|
2020-09-10 18:11:21 -04:00
|
|
|
/* for css linking images (and viz plugin thumbnails) */
|
2016-07-27 19:57:05 -04:00
|
|
|
{
|
|
|
|
test: /\.png$/,
|
2021-03-04 12:58:16 -05:00
|
|
|
issuer: {
|
2021-09-22 07:24:54 -04:00
|
|
|
not: [/\/src\/assets\/staticPages\//],
|
2021-03-04 12:58:16 -05:00
|
|
|
},
|
2021-09-22 07:24:54 -04:00
|
|
|
type: 'asset',
|
|
|
|
generator: {
|
|
|
|
filename: '[name].[contenthash:8].[ext]',
|
2018-10-11 23:55:40 -04:00
|
|
|
},
|
2016-07-27 19:57:05 -04:00
|
|
|
},
|
2021-03-04 12:58:16 -05:00
|
|
|
{
|
|
|
|
test: /\.png$/,
|
2021-09-22 07:24:54 -04:00
|
|
|
issuer: /\/src\/assets\/staticPages\//,
|
|
|
|
type: 'asset',
|
2021-03-04 12:58:16 -05:00
|
|
|
},
|
2020-06-16 20:30:10 -04:00
|
|
|
{
|
|
|
|
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
|
2021-09-22 07:24:54 -04:00
|
|
|
issuer: /\.([jt])sx?$/,
|
2020-06-16 20:30:10 -04:00
|
|
|
use: ['@svgr/webpack'],
|
|
|
|
},
|
2016-07-27 19:57:05 -04:00
|
|
|
{
|
2018-10-11 23:55:40 -04:00
|
|
|
test: /\.(jpg|gif)$/,
|
2021-09-22 07:24:54 -04:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: '[name].[contenthash:8].[ext]',
|
2018-10-11 23:55:40 -04:00
|
|
|
},
|
2016-07-27 19:57:05 -04:00
|
|
|
},
|
2016-07-14 22:50:47 -04:00
|
|
|
/* for font-awesome */
|
2016-07-27 19:57:05 -04:00
|
|
|
{
|
2021-09-22 07:24:54 -04:00
|
|
|
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
|
|
type: 'asset/resource',
|
2016-07-27 19:57:05 -04:00
|
|
|
},
|
2021-04-27 15:03:35 -04:00
|
|
|
{
|
|
|
|
test: /\.ya?ml$/,
|
|
|
|
include: ROOT_DIR,
|
|
|
|
loader: 'js-yaml-loader',
|
|
|
|
},
|
Map visualization (#650)
* simple mapbox viz
use react-map-gl
superclustering of long/lat points
Added hook for map style, huge performance boost from bounding box fix, added count text on clusters
variable gradient size based on metric count
Ability to aggregate over any point property
This needed a change in the supercluster npm module, a PR was placed here:
https://github.com/mapbox/supercluster/pull/12
Aggregator function option in explore, tweaked visual defaults
better radius size management
clustering radius, point metric/unit options
scale cluster labels that don't fit, non-numeric labels for points
Minor fixes, label field affects points, text changes
serve mapbox apikey for slice
global opacity, viewport saves (hacky), bug in point labels
fixing mapbox-gl dependency
mapbox_api_key in config
expose row_limit, fix minor bugs
Add renderWhileDragging flag, groupby. Only show numerical columns for point radius
Implicitly group by lng/lat columns and error when label doesn't match groupby
'Fix' radius in miles problem, still some jankiness
derived fields cannot be typed as of now -> reverting numerical number change
better grouping error checking, expose count(*) for labelling
Custom colour for clusters/points + smart text colouring
Fixed bad positioning and overflow in explore view + small bugs + added thumbnail
* landscaping & eslint & use izip
* landscapin'
* address js code review
2016-06-24 17:16:51 -04:00
|
|
|
],
|
2016-03-18 02:44:58 -04:00
|
|
|
},
|
2016-07-14 22:50:47 -04:00
|
|
|
externals: {
|
|
|
|
cheerio: 'window',
|
|
|
|
'react/lib/ExecutionEnvironment': true,
|
2016-07-21 00:32:20 -04:00
|
|
|
'react/lib/ReactContext': true,
|
2016-07-14 22:50:47 -04:00
|
|
|
},
|
2018-09-04 13:39:05 -04:00
|
|
|
plugins,
|
2020-03-17 18:37:07 -04:00
|
|
|
devtool: false,
|
|
|
|
};
|
|
|
|
|
2020-03-26 19:55:22 -04:00
|
|
|
let proxyConfig = getProxyConfig();
|
2020-03-17 18:37:07 -04:00
|
|
|
|
|
|
|
if (isDevMode) {
|
2020-03-19 17:57:39 -04:00
|
|
|
config.devtool = 'eval-cheap-module-source-map';
|
2020-03-17 18:37:07 -04:00
|
|
|
config.devServer = {
|
2021-09-22 07:24:54 -04:00
|
|
|
onBeforeSetupMiddleware(devServer) {
|
2020-03-26 19:55:22 -04:00
|
|
|
// load proxy config when manifest updates
|
2021-09-22 07:24:54 -04:00
|
|
|
const { afterEmit } = getCompilerHooks(devServer.compiler);
|
|
|
|
afterEmit.tap('ManifestPlugin', manifest => {
|
2020-03-26 19:55:22 -04:00
|
|
|
proxyConfig = getProxyConfig(manifest);
|
|
|
|
});
|
2020-03-17 18:37:07 -04:00
|
|
|
},
|
2018-09-04 13:39:05 -04:00
|
|
|
historyApiFallback: true,
|
|
|
|
hot: true,
|
|
|
|
port: devserverPort,
|
|
|
|
// Only serves bundled files from webpack-dev-server
|
|
|
|
// and proxy everything else to Superset backend
|
2020-03-17 18:37:07 -04:00
|
|
|
proxy: [
|
|
|
|
// functions are called for every request
|
2021-01-10 20:26:35 -05:00
|
|
|
() => proxyConfig,
|
2020-03-17 18:37:07 -04:00
|
|
|
],
|
2021-09-22 07:24:54 -04:00
|
|
|
client: {
|
|
|
|
overlay: { errors: true, warnings: false },
|
|
|
|
logging: 'error',
|
|
|
|
},
|
|
|
|
static: path.join(process.cwd(), '../static/assets'),
|
2020-03-17 18:37:07 -04:00
|
|
|
};
|
2020-03-19 17:57:39 -04:00
|
|
|
|
2021-05-03 19:23:42 -04:00
|
|
|
// make sure to use @emotion/* modules in the root directory
|
|
|
|
fs.readdirSync(path.resolve(APP_DIR, './node_modules/@emotion'), pkg => {
|
|
|
|
config.resolve.alias[pkg] = path.resolve(
|
|
|
|
APP_DIR,
|
|
|
|
'./node_modules/@emotion',
|
|
|
|
pkg,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-03-19 17:57:39 -04:00
|
|
|
// find all the symlinked plugins and use their source code for imports
|
|
|
|
let hasSymlink = false;
|
2020-09-18 12:05:57 -04:00
|
|
|
Object.entries(packageConfig.dependencies).forEach(([pkg, version]) => {
|
2020-03-19 17:57:39 -04:00
|
|
|
const srcPath = `./node_modules/${pkg}/src`;
|
|
|
|
if (/superset-ui/.test(pkg) && fs.existsSync(srcPath)) {
|
|
|
|
console.log(
|
|
|
|
`[Superset Plugin] Use symlink source for ${pkg} @ ${version}`,
|
|
|
|
);
|
|
|
|
// only allow exact match so imports like `@superset-ui/plugin-name/lib`
|
|
|
|
// and `@superset-ui/plugin-name/esm` can still work.
|
|
|
|
config.resolve.alias[`${pkg}$`] = `${pkg}/src`;
|
2021-01-07 02:36:24 -05:00
|
|
|
delete config.resolve.alias[pkg];
|
2020-03-19 17:57:39 -04:00
|
|
|
hasSymlink = true;
|
|
|
|
}
|
2020-09-18 12:05:57 -04:00
|
|
|
});
|
2020-03-19 17:57:39 -04:00
|
|
|
if (hasSymlink) {
|
|
|
|
console.log(''); // pure cosmetic new line
|
|
|
|
}
|
2018-09-27 15:49:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bundle analyzer is disabled by default
|
|
|
|
// Pass flag --analyzeBundle=true to enable
|
|
|
|
// e.g. npm run build -- --analyzeBundle=true
|
|
|
|
if (analyzeBundle) {
|
2020-09-10 18:11:21 -04:00
|
|
|
config.plugins.push(new BundleAnalyzerPlugin({ analyzerPort }));
|
2018-09-27 15:49:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Speed measurement is disabled by default
|
|
|
|
// Pass flag --measure=true to enable
|
|
|
|
// e.g. npm run build -- --measure=true
|
|
|
|
const smp = new SpeedMeasurePlugin({
|
|
|
|
disable: !measure,
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = smp.wrap(config);
|