registration
This commit is contained in:
25
frontend/style/node_modules/date-fns/docs/webpack.md
generated
vendored
25
frontend/style/node_modules/date-fns/docs/webpack.md
generated
vendored
@@ -16,11 +16,11 @@ export const supportedLocales = ["en-US", "de", "pl", "it"];
|
||||
We could also have a function that formats the date:
|
||||
|
||||
```js
|
||||
const getLocale = (locale) => import(`date-fns/locale/${locale}/index.js`); // or require() if using CommonJS
|
||||
const getLocale = (locale) => import(`date-fns-locale/locale/${locale}.js`); // or require() if using CommonJS
|
||||
|
||||
const formatDate = (date, formatStyle, locale) => {
|
||||
return format(date, formatStyle, {
|
||||
locale: getLocale(locale),
|
||||
locale: getLocale(locale).default,
|
||||
});
|
||||
};
|
||||
```
|
||||
@@ -30,17 +30,22 @@ In order to exclude unused languages we can use webpacks [ContextReplacementPlug
|
||||
`webpack.config.js`:
|
||||
|
||||
```js
|
||||
import webpack from 'webpack'
|
||||
import { supportedLocales } from './config.js'
|
||||
import webpack from "webpack";
|
||||
import { supportedLocales } from "./config.js";
|
||||
|
||||
export default const config = {
|
||||
export default config = {
|
||||
resolve: {
|
||||
alias: {
|
||||
"date-fns-locale": path.dirname(require.resolve("date-fns/package.json")),
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new webpack.ContextReplacementPlugin(
|
||||
/^date-fns[/\\]locale$/,
|
||||
new RegExp(`\\.[/\\\\](${supportedLocales.join('|')})[/\\\\]index\\.js$`)
|
||||
)
|
||||
]
|
||||
}
|
||||
/date-fns[/\\]locale/,
|
||||
new RegExp(`(${locales.join("|")})\.js$`),
|
||||
),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
This results in a language bundle of ~23kb .
|
||||
|
||||
Reference in New Issue
Block a user