diff --git a/generator/index.js b/generator/index.js index 7a59cdf..c02bbd4 100644 --- a/generator/index.js +++ b/generator/index.js @@ -1,13 +1,16 @@ -module.exports = (api, opts, rootOptions) => { +module.exports = (api, opts) => { const utils = require('./utils')(api) api.extendPackage({ dependencies: { - 'element-plus': '^1.0.2-beta.28' + 'element-plus': '^1.0.2-beta.71' } }) - api.injectImports(api.entryFile, `import installElementPlus from './plugins/element'`) + api.injectImports(api.entryFile, [ + `import installElementPlus from './plugins/element.js'`, + `import locale from 'element-plus/lib/locale/lang/${opts.lang}.js'` + ]) api.render({ './src/plugins/element.js': './templates/src/plugins/element.js', @@ -39,12 +42,23 @@ module.exports = (api, opts, rootOptions) => { const lines = contentMain.split(/\r?\n/g) const renderIndex = lines.findIndex(line => line.match(/createApp\(App\)(\.use\(\w*\))*\.mount\(['"]#app['"]\)/)) - const renderContent = lines[renderIndex] - lines[renderIndex] = `const app = createApp(App)` - lines[renderIndex + 1] = `installElementPlus(app)` - lines[renderIndex + 2] = renderContent.replace('createApp\(App\)','app') - fs.writeFileSync(api.resolve(api.entryFile), lines.join(EOL), { encoding: 'utf-8' }) + if (renderIndex >= 0) { + const renderContent = lines[renderIndex] + lines[renderIndex] = `const app = createApp({ + render() { + return ( + + + + ) + }, + })` + lines[renderIndex + 1] = `installElementPlus(app)` + lines[renderIndex + 2] = renderContent.replace('createApp\(App\)','app') + + fs.writeFileSync(api.resolve(api.entryFile), lines.join(EOL), { encoding: 'utf-8' }) + } }) api.onCreateComplete(() => { diff --git a/generator/templates/src/plugins/element.js b/generator/templates/src/plugins/element.js index 709a72c..39255cf 100644 --- a/generator/templates/src/plugins/element.js +++ b/generator/templates/src/plugins/element.js @@ -5,27 +5,15 @@ import '../element-variables.scss' <%_ } else { _%> import 'element-plus/lib/theme-chalk/index.css' <%_ } _%> -<%_ if (options.lang !== 'en') { _%> -import locale from 'element-plus/lib/locale/lang/<%= options.lang %>' -<%_ } _%> <%_ } else { _%> -import { ElButton } from 'element-plus' -<%_ if (options.lang !== 'en') { _%> -import lang from 'element-plus/lib/locale/lang/<%= options.lang %>' -import locale from 'element-plus/lib/locale' -<%_ }} _%> +import { ElButton, ElConfigProvider } from 'element-plus' +<%_ } _%> export default (app) => { <%_ if (options.import === 'full') { _%> - <%_ if (options.lang !== 'en') { _%> - app.use(ElementPlus, { locale }) - <%_ } else { _%> app.use(ElementPlus) - <%_ } _%> <%_ } else { _%> - <%_ if (options.lang !== 'en') { _%> - locale.use(lang) - <%_ } _%> app.use(ElButton) + app.use(ElConfigProvider) <%_ } _%> } \ No newline at end of file