fix(build): locale export default (#5576)

This commit is contained in:
三咲智子
2022-01-24 23:37:19 +08:00
committed by GitHub
parent 3c16321110
commit 0464c06d92
2 changed files with 11 additions and 30 deletions

View File

@ -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'
@ -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,
@ -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,

View File

@ -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>
```
@ -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>