wepy.config.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. const path = require('path')
  2. const prod = process.env.NODE_ENV === 'production'
  3. module.exports = {
  4. wpyExt: '.wpy',
  5. build: {
  6. web: {
  7. htmlTemplate: path.join('src', 'index.template.html'),
  8. htmlOutput: path.join('web', 'index.html'),
  9. jsOutput: path.join('web', 'index.js')
  10. }
  11. },
  12. resolve: {
  13. alias: {
  14. 'lib': path.join(__dirname, 'src/lib/lib'),
  15. 'md5': path.join(__dirname, 'src/lib/md5'),
  16. '@': path.join(__dirname, 'src')
  17. },
  18. modules: ['node_modules']
  19. },
  20. // eslint: true,
  21. compilers: {
  22. // less: {
  23. // compress: true
  24. // },
  25. sass: {
  26. outputStyle: 'compressed'
  27. },
  28. babel: {
  29. sourceMap: false,
  30. presets: [
  31. 'env'
  32. ],
  33. plugins: [
  34. 'transform-class-properties',
  35. 'transform-decorators-legacy',
  36. 'transform-object-rest-spread',
  37. 'transform-export-extensions'
  38. ]
  39. }
  40. },
  41. plugins: {
  42. imgbase64: {
  43. css: false,
  44. html: true,
  45. output: 'dist',
  46. // fileType: 'scss',
  47. path: '/src/img'
  48. },
  49. replace: {
  50. filter: /lib\.js$/,
  51. config: {
  52. find: /__ENV__/g,
  53. replace: process.env.NODE_ENV
  54. }
  55. }
  56. },
  57. appConfig: {
  58. noPromiseAPI: ['createSelectorQuery']
  59. }
  60. }
  61. if (prod) {
  62. delete module.exports.compilers.babel.sourcesMap
  63. // 压缩sass
  64. module.exports.compilers['sass'] = {
  65. outputStyle: 'compressed'
  66. }
  67. // 压缩less
  68. // module.exports.compilers['less'] = {
  69. // compress: true
  70. // }
  71. // 压缩js
  72. module.exports.plugins = {
  73. uglifyjs: {
  74. filter: /\.js$/,
  75. config: {}
  76. },
  77. imagemin: {
  78. filter: /\.(jpg|png|jpeg)$/,
  79. config: {
  80. jpg: {
  81. quality: 80
  82. },
  83. png: {
  84. quality: 80
  85. }
  86. }
  87. },
  88. imgbase64: {
  89. css: false,
  90. html: true,
  91. output: 'dist',
  92. // fileType: 'scss',
  93. path: '/src/img'
  94. },
  95. replace: {
  96. filter: /lib\.js$/,
  97. config: {
  98. find: /__ENV__/g,
  99. replace: process.env.NODE_ENV
  100. }
  101. }
  102. }
  103. }