Skip to content

Commit

Permalink
chore(moment): readd moment-plugin for peer deps
Browse files Browse the repository at this point in the history
  • Loading branch information
msyavuz committed Dec 23, 2024
1 parent 97f88be commit 5aa5581
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
37 changes: 37 additions & 0 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
"less-loader": "^12.2.0",
"mini-css-extract-plugin": "^2.9.0",
"mock-socket": "^9.3.1",
"moment-locales-webpack-plugin": "^1.2.0",
"node-fetch": "^2.6.7",
"open-cli": "^8.0.0",
"po2json": "^0.4.5",
Expand Down
29 changes: 29 additions & 0 deletions superset-frontend/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const {
Expand All @@ -41,6 +42,24 @@ const APP_DIR = path.resolve(__dirname, './');
// output dir
const BUILD_DIR = path.resolve(__dirname, '../superset/static/assets');
const ROOT_DIR = path.resolve(__dirname, '..');
const TRANSLATIONS_DIR = path.resolve(__dirname, '../superset/translations');

const getAvailableTranslationCodes = () => {
if (process.env.BUILD_TRANSLATIONS === 'true') {
const LOCALE_CODE_MAPPING = {
zh: 'zh-cn',
};
const files = fs.readdirSync(TRANSLATIONS_DIR);
return files
.filter(file =>
fs.statSync(path.join(TRANSLATIONS_DIR, file)).isDirectory(),
)
.filter(dirName => !dirName.startsWith('__'))
.map(dirName => dirName.replace('_', '-'))
.map(dirName => LOCALE_CODE_MAPPING[dirName] || dirName);
}
return [];
};

const {
mode = 'development',
Expand Down Expand Up @@ -140,6 +159,9 @@ const plugins = [
chunks: [],
filename: '500.html',
}),
new MomentLocalesPlugin({
localesToKeep: getAvailableTranslationCodes(),
}),
];

if (!process.env.CI) {
Expand Down Expand Up @@ -274,6 +296,7 @@ const config = {
'antd',
'@ant-design.*',
'.*bootstrap',
'moment',
'jquery',
'core-js.*',
'@emotion.*',
Expand Down Expand Up @@ -305,6 +328,12 @@ const config = {
// TODO: remove Handlebars alias once Handlebars NPM package has been updated to
// correctly support webpack import (https://github.com/handlebars-lang/handlebars.js/issues/953)
handlebars: 'handlebars/dist/handlebars.js',
/*
Temporary workaround to prevent Webpack from resolving moment locale
files, which are unnecessary for this project and causing build warnings.
This prevents "Module not found" errors for moment locale files.
*/
'moment/min/moment-with-locales': false,
// Temporary workaround to allow Storybook 8 to work with existing React v16-compatible stories.
// Remove below alias once React has been upgreade to v18.
'@storybook/react-dom-shim': path.resolve(
Expand Down

0 comments on commit 5aa5581

Please sign in to comment.