vite.config.build.taro.vue.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { defineConfig } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import path from 'path';
  4. import config from './package.json';
  5. import { terser } from 'rollup-plugin-terser';
  6. const banner = `/*!
  7. * ${config.name} v${config.version} ${new Date()}
  8. * (c) 2022 @jdf2e.
  9. * Released under the MIT License.
  10. */`;
  11. export default defineConfig({
  12. resolve: {
  13. alias: [{ find: '@', replacement: path.resolve(__dirname, './src') }]
  14. },
  15. css: {
  16. preprocessorOptions: {
  17. scss: {
  18. // example : additionalData: `@import "./src/design/styles/variables";`
  19. // dont need include file extend .scss
  20. additionalData: `@import "@/packages/styles/variables.scss";@import "@/sites/assets/styles/variables.scss";`
  21. }
  22. }
  23. },
  24. plugins: [
  25. vue({
  26. template: {
  27. compilerOptions: {
  28. isCustomElement: (tag) => {
  29. return (
  30. tag.startsWith('scroll-view') ||
  31. tag.startsWith('swiper') ||
  32. tag.startsWith('swiper-item') ||
  33. tag.startsWith('picker')
  34. );
  35. },
  36. whitespace: 'preserve'
  37. }
  38. }
  39. })
  40. ],
  41. build: {
  42. minify: false,
  43. rollupOptions: {
  44. // 请确保外部化那些你的库中不需要的依赖
  45. external: ['vue', 'vue-router', '@tarojs/taro'],
  46. output: {
  47. banner,
  48. // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
  49. globals: {
  50. vue: 'Vue'
  51. },
  52. plugins: [
  53. terser({
  54. compress: {
  55. drop_console: true,
  56. drop_debugger: true
  57. }
  58. })
  59. ]
  60. }
  61. },
  62. lib: {
  63. entry: 'src/packages/nutui.taro.vue.build.ts',
  64. name: 'nutui',
  65. fileName: 'nutui',
  66. formats: ['es', 'umd']
  67. }
  68. }
  69. });