123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const path = require('path')
  2. const sassImportor = function (url) {
  3. const reg = /^@styles\/(.*)/
  4. return {
  5. file: reg.test(url) ? path.resolve(__dirname, '..', 'src/styles', url.match(reg)[1]) : url
  6. }
  7. }
  8. const config = {
  9. projectName: 'mini-chengjiao',
  10. date: '2019-5-7',
  11. designWidth: 750,
  12. deviceRatio: {
  13. '640': 2.34 / 2,
  14. '750': 1,
  15. '828': 1.81 / 2
  16. },
  17. sourceRoot: 'src',
  18. outputRoot: 'dist',
  19. plugins: {
  20. babel: {
  21. sourceMap: true,
  22. presets: [
  23. ['env', {
  24. modules: false
  25. }]
  26. ],
  27. plugins: [
  28. 'transform-decorators-legacy',
  29. 'transform-class-properties',
  30. 'transform-object-rest-spread'
  31. ]
  32. },
  33. sass: {
  34. importer: sassImportor
  35. }
  36. },
  37. alias: {
  38. '@actions': path.resolve(__dirname, '..', 'src/actions'),
  39. '@assets': path.resolve(__dirname, '..', 'src/assets'),
  40. '@components': path.resolve(__dirname, '..', 'src/components'),
  41. '@constants': path.resolve(__dirname, '..', 'src/constants'),
  42. '@reducers': path.resolve(__dirname, '..', 'src/reducers'),
  43. '@styles': path.resolve(__dirname, '..', 'src/styles'),
  44. '@utils': path.resolve(__dirname, '..', 'src/utils'),
  45. '@services': path.resolve(__dirname, '..', 'src/services'),
  46. '@lib': path.resolve(__dirname, '..', 'src/lib'),
  47. },
  48. copy: {
  49. patterns: [
  50. ],
  51. options: {
  52. }
  53. },
  54. weapp: {
  55. module: {
  56. postcss: {
  57. autoprefixer: {
  58. enable: true,
  59. config: {
  60. browsers: [
  61. 'last 3 versions',
  62. 'Android >= 4.1',
  63. 'ios >= 8'
  64. ]
  65. }
  66. },
  67. pxtransform: {
  68. enable: true,
  69. config: {
  70. }
  71. },
  72. url: {
  73. enable: true,
  74. config: {
  75. limit: 10240 // 设定转换尺寸上限
  76. }
  77. },
  78. cssModules: {
  79. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  80. config: {
  81. namingPattern: 'module', // 转换模式,取值为 global/module
  82. generateScopedName: '[name]__[local]___[hash:base64:5]'
  83. }
  84. }
  85. }
  86. }
  87. },
  88. h5: {
  89. publicPath: '/',
  90. staticDirectory: 'static',
  91. module: {
  92. postcss: {
  93. autoprefixer: {
  94. enable: true,
  95. config: {
  96. browsers: [
  97. 'last 3 versions',
  98. 'Android >= 4.1',
  99. 'ios >= 8'
  100. ]
  101. }
  102. },
  103. cssModules: {
  104. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  105. config: {
  106. namingPattern: 'module', // 转换模式,取值为 global/module
  107. generateScopedName: '[name]__[local]___[hash:base64:5]'
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. module.exports = function (merge) {
  115. if (process.env.NODE_ENV === 'development') {
  116. return merge({}, config, require('./dev'))
  117. }
  118. return merge({}, config, require('./prod'))
  119. }