Skip to content

Commit

Permalink
fix(build): locale export default (element-plus#5576)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored Jan 24, 2022
1 parent 3c16321 commit 0464c06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 30 deletions.
6 changes: 3 additions & 3 deletions build/full-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import replace from '@rollup/plugin-replace'
import filesize from 'rollup-plugin-filesize'
import { parallel } from 'gulp'
import glob from 'fast-glob'
import { camelCase, capitalize } from 'lodash'
import { camelCase, upperFirst } from 'lodash'
import { version } from '../packages/element-plus/version'
import { reporter } from './plugins/size-reporter'
import { ElementPlusAlias } from './plugins/element-plus-alias'
Expand Down Expand Up @@ -91,7 +91,7 @@ async function buildFullLocale(minify: boolean) {
return Promise.all(
files.map(async (file) => {
const filename = path.basename(file, '.ts')
const name = capitalize(camelCase(filename))
const name = upperFirst(camelCase(filename))

const bundle = await rollup({
input: file,
Expand All @@ -112,7 +112,7 @@ async function buildFullLocale(minify: boolean) {
'dist/locale',
formatBundleFilename(filename, minify, 'js')
),
exports: 'named',
exports: 'default',
name: `ElementPlusLocale${name}`,
sourcemap: minify,
banner,
Expand Down
35 changes: 8 additions & 27 deletions docs/en-US/guide/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ If you are using Element Plus via CDN, then you need to do this, let's again tak
unpkg as an example

```html
<script src="//unpkg.com/element-plus/dist/locale/zh-cn">
<script>
<script src="//unpkg.com/element-plus/dist/locale/zh-cn"></script>
<script>
app.use(ElementPlus, {
locale: ElementPlus.lang.zhCn
locale: ElementPlusLocaleZhCn,
})
</script>
```
Expand Down Expand Up @@ -130,27 +130,8 @@ If you need any other languages, [PR](https://github.com/element-plus/element-pl
is always welcomed, you only need to add a language file at
[here](https://github.com/element-plus/element-plus/tree/dev/packages/locale/lang).

## FAQs

### If I want to replace the default language pack to reduce the size, how do I do?

When the default language of your app is not **English**, you will be going to need
to import another language file, which will increase the bundle size since you have
both **English** and **Your desired language** bundled,
you can use the plugin [NormalModuleReplacementPlugin](https://webpack.js.org/plugins/normal-module-replacement-plugin/#root)
provided by [webpack](https://webpack.js.org) to replace the default language file,
so that you will only get **1** language file bundled.
Add the code below into your `webpack.config.js` to get it work.

> webpack.config.js
```typescript
{
plugins: [
new webpack.NormalModuleReplacementPlugin(
/element-plus[\/\\]lib[\/\\]locale[\/\\]lang[\/\\]en/,
'element-plus/lib/locale/lang/zh-cn'
),
]
}
```
<style>
.language-list {
list-style: disc
}
</style>

0 comments on commit 0464c06

Please sign in to comment.