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

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

index.js —— 通用配置

  1. const config = {
  2. // 项目名称
  3. projectName: 'Awesome Next',
  4. // 项目创建日期
  5. date: '2020-6-2',
  6. // 设计稿尺寸
  7. designWidth: 750,
  8. // 设计稿尺寸换算规则
  9. deviceRatio: {
  10. 640: 2.34 / 2,
  11. 750: 1,
  12. 828: 1.81 / 2
  13. },
  14. // 项目源码目录
  15. sourceRoot: 'src',
  16. // 项目产出目录
  17. outputRoot: 'dist',
  18. // 编译插件配置
  19. plugins: [],
  20. // 全局变量设置
  21. defineConstants: {},
  22. // 文件 copy 配置
  23. copy: {
  24. patterns: [
  25. ],
  26. options: {
  27. }
  28. },
  29. // 框架,react,nerv,vue 三选一
  30. framework: 'react',
  31. // 小程序端专用配置
  32. mini: {
  33. postcss: {
  34. autoprefixer: {
  35. enable: true
  36. },
  37. // 小程序端样式引用本地资源内联配置
  38. url: {
  39. enable: true,
  40. config: {
  41. limit: 10240
  42. }
  43. }
  44. },
  45. // 自定义 Webpack 配置
  46. webpackChain: {},
  47. },
  48. // H5 端专用配置
  49. h5: {
  50. publicPath: '/',
  51. staticDirectory: 'static',
  52. postcss: {
  53. autoprefixer: {
  54. enable: true
  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. };