编译配置存放于项目根目录下 config 目录中,包含三个文件

  • index.js 是通用配置
  • dev.js 是项目预览时的配置
  • prod.js 是项目打包时的配置

index.js —— 通用配置

  1. const config = {
  2. // 项目名称
  3. projectName: 'kj',
  4. // 项目创建日期
  5. date: '2018-6-8',
  6. // 设计稿尺寸
  7. designWidth: 750,
  8. // 项目源码目录
  9. sourceRoot: 'src',
  10. // 项目产出目录
  11. outputRoot: 'dist',
  12. // 通用插件配置
  13. plugins: {
  14. babel: {
  15. sourceMap: true,
  16. presets: ['env'],
  17. plugins: ['transform-class-properties', 'transform-decorators-legacy', 'transform-object-rest-spread']
  18. }
  19. },
  20. // 全局变量设置
  21. defineConstants: {},
  22. // 文件 copy 配置
  23. copy: {
  24. patterns: [
  25. ],
  26. options: {
  27. }
  28. },
  29. // 小程序端专用配置
  30. weapp: {
  31. module: {
  32. postcss: {
  33. autoprefixer: {
  34. enable: true
  35. },
  36. // 小程序端样式引用本地资源内联配置
  37. url: {
  38. enable: true,
  39. config: {
  40. limit: 10240
  41. }
  42. }
  43. }
  44. }
  45. },
  46. // H5 端专用配置
  47. h5: {
  48. publicPath: '/',
  49. staticDirectory: 'static',
  50. module: {
  51. postcss: {
  52. autoprefixer: {
  53. enable: true
  54. }
  55. }
  56. },
  57. // 自定义 webpack 配置
  58. webpackChain: {},
  59. devServer: {}
  60. }
  61. };
  62. module.exports = function(merge) {
  63. if (process.env.NODE_ENV === 'development') {
  64. return merge({}, config, require('./dev'));
  65. }
  66. return merge({}, config, require('./prod'));
  67. };