-
-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Parcel with Webpack 5 (#432)
- Loading branch information
Showing
8 changed files
with
177 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
import getUserLocale from 'get-user-locale'; | ||
|
||
function getFormatter(options) { | ||
return (locale, date) => date.toLocaleString(locale || getUserLocale(), options); | ||
} | ||
|
||
/** | ||
* Changes the hour in a Date to ensure right date formatting even if DST is messed up. | ||
* Workaround for bug in WebKit and Firefox with historical dates. | ||
* For more details, see: | ||
* https://bugs.chromium.org/p/chromium/issues/detail?id=750465 | ||
* https://bugzilla.mozilla.org/show_bug.cgi?id=1385643 | ||
* | ||
* @param {Date} date Date. | ||
*/ | ||
function toSafeHour(date) { | ||
const safeDate = new Date(date); | ||
return new Date(safeDate.setHours(12)); | ||
} | ||
|
||
function getSafeFormatter(options) { | ||
return (locale, date) => getFormatter(options)(locale, toSafeHour(date)); | ||
} | ||
|
||
const formatDateOptions = { day: 'numeric', month: 'numeric', year: 'numeric' }; | ||
|
||
export const formatDate = getSafeFormatter(formatDateOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
import PropTypes from 'prop-types'; | ||
|
||
export const isValue = PropTypes.oneOfType([ | ||
PropTypes.instanceOf(Date), | ||
PropTypes.arrayOf(PropTypes.instanceOf(Date)), | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const path = require('path'); | ||
|
||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | ||
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); | ||
|
||
const isProduction = process.env.NODE_ENV === 'production'; | ||
const isDevelopment = !isProduction; | ||
|
||
module.exports = { | ||
mode: isProduction ? 'production' : 'development', | ||
bail: isProduction, | ||
context: path.join(__dirname), | ||
entry: { | ||
src: './index.jsx', | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: '[name].[chunkhash:8].js', | ||
}, | ||
resolve: { | ||
extensions: ['.js', '.jsx'], | ||
symlinks: false, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.jsx?$/, | ||
exclude: /node_modules(?!\/react-calendar)/, | ||
use: [ | ||
{ | ||
loader: 'babel-loader', | ||
options: { | ||
babelrcRoots: ['.', '../'], | ||
plugins: [isDevelopment && 'react-refresh/babel'].filter(Boolean), | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
test: /\.less$/, | ||
use: [ | ||
isProduction ? MiniCssExtractPlugin.loader : 'style-loader', | ||
'css-loader', | ||
'less-loader', | ||
], | ||
}, | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
isProduction ? MiniCssExtractPlugin.loader : 'style-loader', | ||
'css-loader', | ||
], | ||
}, | ||
].filter(Boolean), | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
template: 'index.html', | ||
}), | ||
isProduction && new MiniCssExtractPlugin({ | ||
filename: '[name].[chunkhash:8].css', | ||
chunkFilename: '[name].[chunkhash:8].css', | ||
}), | ||
isDevelopment && new ReactRefreshWebpackPlugin(), | ||
].filter(Boolean), | ||
optimization: { | ||
moduleIds: 'named', | ||
}, | ||
stats: { | ||
assetsSort: '!size', | ||
entrypoints: false, | ||
}, | ||
devServer: { | ||
compress: true, | ||
historyApiFallback: true, // respond to 404s with index.html | ||
host: 'localhost', | ||
hot: true, // enable HMR on the server | ||
port: 3000, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters