index.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { defineConfig, type UserConfigExport } from '@tarojs/cli'
  2. import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
  3. import { VueLoaderPlugin } from 'vue-loader'
  4. import { resolve } from 'path'
  5. import ComponentsPlugin from 'unplugin-vue-components/webpack'
  6. const NutUIResolver = () => {
  7. return (name) => {
  8. if (name.startsWith('Nut')) {
  9. const partialName = name.slice(3)
  10. return {
  11. name: partialName,
  12. from: '@nutui/nutui-taro',
  13. sideEffects: `@nutui/nutui-taro/dist/packages/${partialName.toLowerCase()}/style`,
  14. }
  15. }
  16. }
  17. }
  18. export default defineConfig({
  19. projectName: 'miniprogram-linejoy',
  20. date: '2023-4-3',
  21. designWidth: 375,
  22. deviceRatio: {
  23. 640: 2.34 / 2,
  24. 750: 1,
  25. 828: 1.81 / 2,
  26. 375: 2 / 1
  27. },
  28. sourceRoot: 'src',
  29. outputRoot: 'dist',
  30. plugins: ['@tarojs/plugin-html'],
  31. sass: {
  32. data: `
  33. @import "@nutui/nutui-taro/dist/styles/variables.scss";
  34. @import "src/assets/styles/variables.scss";
  35. @import "src/assets/styles/mixins.scss";
  36. `
  37. },
  38. defineConstants: {
  39. },
  40. copy: {
  41. patterns: [
  42. ],
  43. options: {
  44. }
  45. },
  46. framework: 'vue3',
  47. compiler: 'webpack5',
  48. cache: {
  49. enable: false // Webpack 持久化缓存配置,建议开启,默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
  50. },
  51. mini: {
  52. postcss: {
  53. pxtransform: {
  54. enable: true,
  55. config: {
  56. }
  57. },
  58. url: {
  59. enable: true,
  60. config: {
  61. limit: 1024 // 设定转换尺寸上限
  62. }
  63. },
  64. cssModules: {
  65. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  66. config: {
  67. namingPattern: 'module', // 转换模式,取值为 global/module
  68. generateScopedName: '[name]__[local]___[hash:base64:5]'
  69. }
  70. }
  71. },
  72. webpackChain(chain) {
  73. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  74. chain.plugin('unplugin-vue-components').use(
  75. ComponentsPlugin({
  76. resolvers: [NutUIResolver()],
  77. })
  78. )
  79. chain.resolve.alias
  80. .set('@', resolve(__dirname, '..', 'src'))
  81. }
  82. },
  83. h5: {
  84. publicPath: '/',
  85. staticDirectory: 'static',
  86. postcss: {
  87. autoprefixer: {
  88. enable: true,
  89. config: {
  90. }
  91. },
  92. cssModules: {
  93. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  94. config: {
  95. namingPattern: 'module', // 转换模式,取值为 global/module
  96. generateScopedName: '[name]__[local]___[hash:base64:5]'
  97. }
  98. }
  99. },
  100. webpackChain(chain) {
  101. chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
  102. chain.plugin('unplugin-vue-components').use(
  103. ComponentsPlugin({
  104. resolvers: [NutUIResolver()],
  105. })
  106. )
  107. chain.resolve.alias
  108. .set('@', resolve(__dirname, '..', 'src'))
  109. }
  110. }
  111. })