index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. const path = require('path')
  2. // NOTE 在 sass 中通过别名(@ 或 ~)引用需要指定路径
  3. const sassImporter = function(url) {
  4. if (url[0] === '~' && url[1] !== '/') {
  5. return {
  6. file: path.resolve(__dirname, '..', 'node_modules', url.substr(1))
  7. }
  8. }
  9. const reg = /^@styles\/(.*)/
  10. return {
  11. file: reg.test(url) ? path.resolve(__dirname, '..', 'src/styles', url.match(reg)[1]) : url
  12. }
  13. }
  14. const config = {
  15. projectName: 'kede-createRD-h5',
  16. date: '2019-2-1',
  17. designWidth: 750,
  18. deviceRatio: {
  19. '640': 2.34 / 2,
  20. '750': 1,
  21. '828': 1.81 / 2
  22. },
  23. sourceRoot: 'src',
  24. outputRoot: 'dist',
  25. plugins: {
  26. babel: {
  27. sourceMap: true,
  28. presets: [
  29. ['env', {
  30. modules: false
  31. }]
  32. ],
  33. plugins: [
  34. 'transform-decorators-legacy',
  35. 'transform-class-properties',
  36. 'transform-object-rest-spread'
  37. ]
  38. },
  39. sass: {
  40. importer: sassImporter
  41. }
  42. },
  43. defineConstants: {
  44. },
  45. alias: {
  46. '@actions': path.resolve(__dirname, '..', 'src/actions'),
  47. '@assets': path.resolve(__dirname, '..', 'src/assets'),
  48. '@components': path.resolve(__dirname, '..', 'src/components'),
  49. '@constants': path.resolve(__dirname, '..', 'src/constants'),
  50. '@reducers': path.resolve(__dirname, '..', 'src/reducers'),
  51. '@styles': path.resolve(__dirname, '..', 'src/styles'),
  52. '@utils': path.resolve(__dirname, '..', 'src/utils')
  53. },
  54. copy: {
  55. patterns: [
  56. ],
  57. options: {
  58. }
  59. },
  60. weapp: {
  61. module: {
  62. postcss: {
  63. autoprefixer: {
  64. enable: true,
  65. config: {
  66. browsers: [
  67. 'last 3 versions',
  68. 'Android >= 4.1',
  69. 'ios >= 8'
  70. ]
  71. }
  72. },
  73. pxtransform: {
  74. enable: true,
  75. config: {
  76. }
  77. },
  78. url: {
  79. enable: true,
  80. config: {
  81. limit: 10240 // 设定转换尺寸上限
  82. }
  83. },
  84. cssModules: {
  85. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  86. config: {
  87. namingPattern: 'module', // 转换模式,取值为 global/module
  88. generateScopedName: '[name]__[local]___[hash:base64:5]'
  89. }
  90. }
  91. }
  92. }
  93. },
  94. h5: {
  95. // NOTE H5 打包静态资源时带 hash 值,方便缓存、版本管理
  96. publicPath: '/',
  97. staticDirectory: 'static',
  98. output: {
  99. filename: 'js/[name].[hash].js',
  100. chunkFilename: 'js/[name].[chunkhash].js'
  101. },
  102. imageUrlLoaderOption: {
  103. limit: 5000,
  104. name: 'static/images/[name].[hash].[ext]'
  105. },
  106. miniCssExtractPluginOption: {
  107. filename: 'css/[name].[hash].css',
  108. chunkFilename: 'css/[name].[chunkhash].css',
  109. },
  110. module: {
  111. postcss: {
  112. autoprefixer: {
  113. enable: true,
  114. config: {
  115. browsers: [
  116. 'last 3 versions',
  117. 'Android >= 4.1',
  118. 'ios >= 8'
  119. ]
  120. }
  121. },
  122. cssModules: {
  123. enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
  124. config: {
  125. namingPattern: 'module', // 转换模式,取值为 global/module
  126. generateScopedName: '[name]__[local]___[hash:base64:5]'
  127. }
  128. }
  129. }
  130. },
  131. sassLoaderOption: {
  132. importer: sassImporter
  133. }
  134. },
  135. rn: {
  136. appJson: {
  137. // NOTE taro-native-shell 中默认用的是 taroDemo
  138. name: 'taroDemo'
  139. }
  140. }
  141. }
  142. module.exports = function (merge) {
  143. if (process.env.NODE_ENV === 'development') {
  144. return merge({}, config, require('./dev'))
  145. }
  146. return merge({}, config, require('./prod'))
  147. }