index.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. ['preval', ['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. from: 'src/onlineSelling/assets/',
  52. to: 'dist/onlineSelling/assets/'
  53. },
  54. {
  55. from: 'ext.json',
  56. to: 'dist/ext.json'
  57. }
  58. ],
  59. options: {
  60. }
  61. },
  62. weapp: {
  63. module: {
  64. postcss: {
  65. autoprefixer: {
  66. enable: true,
  67. config: {
  68. browsers: [
  69. 'last 3 versions',
  70. 'Android >= 4.1',
  71. 'ios >= 8'
  72. ]
  73. }
  74. },
  75. pxtransform: {
  76. enable: true,
  77. config: {
  78. }
  79. },
  80. url: {
  81. enable: true,
  82. config: {
  83. limit: 10240 // 设定转换尺寸上限
  84. }
  85. },
  86. cssModules: {
  87. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  88. config: {
  89. namingPattern: 'module', // 转换模式,取值为 global/module
  90. generateScopedName: '[name]__[local]___[hash:base64:5]'
  91. }
  92. }
  93. }
  94. }
  95. },
  96. h5: {
  97. publicPath: '/',
  98. staticDirectory: 'static',
  99. module: {
  100. postcss: {
  101. autoprefixer: {
  102. enable: true,
  103. config: {
  104. browsers: [
  105. 'last 3 versions',
  106. 'Android >= 4.1',
  107. 'ios >= 8'
  108. ]
  109. }
  110. },
  111. cssModules: {
  112. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  113. config: {
  114. namingPattern: 'module', // 转换模式,取值为 global/module
  115. generateScopedName: '[name]__[local]___[hash:base64:5]'
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. module.exports = function (merge) {
  123. if (process.env.NODE_ENV === 'development') {
  124. return merge({}, config, require('./dev'))
  125. }
  126. return merge({}, config, require('./prod'))
  127. }