vite.config.build.locale.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { defineConfig } from 'vite';
  2. import path from 'path';
  3. import config from './package.json';
  4. import vue from '@vitejs/plugin-vue';
  5. const banner = `/*!
  6. * ${config.name} v${config.version} ${new Date()}
  7. * (c) 2022 @jdf2e.
  8. * Released under the MIT License.
  9. */`;
  10. let input = {
  11. index: `./src/packages/locale/index`
  12. };
  13. // 动态读取file name
  14. ['zh-CN', 'zh-TW', 'en-US', 'id-ID'].map((file) => {
  15. input[file] = `./src/packages/locale/lang/${file}`;
  16. });
  17. import fs from 'fs-extra';
  18. // 构建index.scss 兼容插件市场按需加载插件
  19. fs.outputFile(path.resolve(__dirname, './dist/packages/locale/index.scss'), ' ', 'utf8', (error) => {});
  20. fs.outputFile(path.resolve(__dirname, './dist/packages/locale/lang/index.scss'), ' ', 'utf8', (error) => {});
  21. export default defineConfig({
  22. plugins: [vue()],
  23. build: {
  24. minify: true,
  25. lib: {
  26. entry: '',
  27. name: 'index',
  28. // fileName: (format) => format,
  29. formats: ['es']
  30. },
  31. rollupOptions: {
  32. // 请确保外部化那些你的库中不需要的依赖
  33. external: ['vue'],
  34. input,
  35. output: {
  36. banner,
  37. dir: path.resolve(__dirname, './dist/packages/locale/lang'),
  38. entryFileNames: '[name].js',
  39. plugins: []
  40. }
  41. },
  42. emptyOutDir: false
  43. }
  44. });