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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 { transformFinalCode, DEFAULT_Components } from './transformFinalCode';
  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. define: {
  13. 'process.env.TARO_ENV': 'process.env.TARO_ENV'
  14. },
  15. resolve: {
  16. alias: [{ find: '@', replacement: path.resolve(__dirname, './src') }]
  17. },
  18. css: {
  19. preprocessorOptions: {
  20. scss: {
  21. // example : additionalData: `@import "./src/design/styles/variables";`
  22. // dont need include file extend .scss
  23. additionalData: `@import "@/packages/styles/variables.scss";@import "@/sites/assets/styles/variables.scss";`
  24. }
  25. }
  26. },
  27. plugins: [
  28. vue({
  29. template: {
  30. compilerOptions: {
  31. isCustomElement: (tag) => {
  32. return (
  33. tag.startsWith('swiper') ||
  34. tag.startsWith('swiper-item') ||
  35. tag.startsWith('scroll-view') ||
  36. tag.startsWith('picker') ||
  37. tag.startsWith('picker-view') ||
  38. tag.startsWith('picker-view-column')
  39. );
  40. },
  41. whitespace: 'preserve',
  42. nodeTransforms: [
  43. (node) => {
  44. if (node.type === 1 /* ELEMENT */) {
  45. const nodeName = node.tag;
  46. if (DEFAULT_Components.has(nodeName)) {
  47. node.tagType = 1; /* 0: ELEMENT, 1: COMPONENT */
  48. }
  49. }
  50. }
  51. ]
  52. }
  53. }
  54. }),
  55. transformFinalCode({
  56. include: ['__VUE/.*/index.taro']
  57. })
  58. ],
  59. build: {
  60. minify: false,
  61. rollupOptions: {
  62. // 请确保外部化那些你的库中不需要的依赖
  63. external: ['vue', 'vue-router', '@tarojs/taro'],
  64. output: {
  65. banner,
  66. // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
  67. globals: {
  68. vue: 'Vue'
  69. },
  70. plugins: []
  71. }
  72. },
  73. lib: {
  74. entry: 'src/packages/nutui.taro.vue.build.ts',
  75. name: 'nutui',
  76. fileName: 'nutui',
  77. formats: ['es', 'umd']
  78. }
  79. }
  80. });