diff --git a/build/build-locale.js b/build/build-locale.js index 7b0404a332..db8e5f9f3f 100644 --- a/build/build-locale.js +++ b/build/build-locale.js @@ -30,7 +30,7 @@ fileList .replace('define(\"', 'define(\"element/locale/') .replace( /global\.(\S*) = mod.exports/, - 'global.ELEMENT.lang = global.ELEMENT.lang || {};\n global.ELEMENT.lang.$1 = mod.exports.default' + 'global.ElementPlus.lang = global.ElementPlus.lang || {};\n global.ElementPlus.lang.$1 = mod.exports.default' ) save(resolve(__dirname, '../lib/umd/locale', `${name}.js`)).write(transformedCode) diff --git a/build/webpack.config.js b/build/webpack.config.js index 26d6f52d18..b737bb0178 100644 --- a/build/webpack.config.js +++ b/build/webpack.config.js @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-var-requires */ const path = require('path') +const webpack = require('webpack') const { VueLoaderPlugin } = require('vue-loader') // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin @@ -14,6 +15,11 @@ let externals = [ }, }, ] +const plugins = [ + new VueLoaderPlugin(), + // new BundleAnalyzerPlugin(), +] +let entry = [path.resolve(__dirname, '../packages/element-plus/index.ts')] if (!isFullMode) { externals.push({ '@popperjs/core': '@popperjs/core', @@ -24,11 +30,13 @@ if (!isFullMode) { }, /^dayjs.*/, /^lodash.*/) +} else { + entry.push(path.resolve(__dirname, '../packages/element-plus/full.ts')) } const config = { mode: 'production', - entry: path.resolve(__dirname, '../packages/element-plus/index.ts'), + entry, output: { path: path.resolve(__dirname, '../lib'), publicPath: '/', @@ -55,10 +63,7 @@ const config = { extensions: ['.ts', '.tsx', '.js', '.json'], }, externals, - plugins: [ - new VueLoaderPlugin(), - // new BundleAnalyzerPlugin(), - ], + plugins, } module.exports = config diff --git a/packages/element-plus/full.ts b/packages/element-plus/full.ts new file mode 100644 index 0000000000..3e6dd8d2b8 --- /dev/null +++ b/packages/element-plus/full.ts @@ -0,0 +1,4 @@ +import dayjs from 'dayjs' + +// expose Day.js to window to make full bundle i18n work +(window as any).dayjs = dayjs diff --git a/website/docs/en-US/i18n.md b/website/docs/en-US/i18n.md index acfaf93c6e..9bad6c3717 100644 --- a/website/docs/en-US/i18n.md +++ b/website/docs/en-US/i18n.md @@ -10,11 +10,22 @@ import 'dayjs/locale/zh-cn' createApp(App).use(ElementPlus, { locale }) ``` - -Or if you are importing Element Plus on demand: +if you are importing Element Plus on demand via **es modules**: ```typescript -import Vue from 'vue' +import { createApp } from 'vue' +import { ElButton, locale } from 'element-plus' +import lang from 'element-plus/lib/locale/lang/zh-cn' +import 'dayjs/locale/zh-cn' + +locale(lang) +createApp(App).component(ElButton.name, ElButton) +``` + +Or if you are importing Element Plus on demand via [babel-plugin-component](#/en-US/component/quickstart#on-demand): + +```typescript +import { createApp } from 'vue' import { ElButton, ElSelect } from 'element-plus' import lang from 'element-plus/lib/locale/lang/zh-cn' import 'dayjs/locale/zh-cn' @@ -24,8 +35,8 @@ import locale from 'element-plus/lib/locale' locale.use(lang) // import components -Vue.component(ElButton.name, ElButton) -Vue.component(ElSelect.name, ElSelect) +createApp(App).component(ElButton.name, ElButton) +createApp(App).component(ElSelect.name, ElSelect) ``` ### Set Day.js locale @@ -190,41 +201,41 @@ app.use(i18n) ### Import via CDN ```html - - + + ``` Compatible with `vue-i18n` ```html - + - + - + + ``` Compatible con `vue-i18n` ```html - + - + - + + + +``` + +Compatible avec `vue-i18n` + +```html + + + + + + ``` -Compatible avec `vue-i18n` - -```html - - - - - - - -``` - Actuellement, Element Plus supporte les langues suivantes: