title: 编译配置

编译配置存放于项目根目录下 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. // babel 编译配置
  13. babel: {
  14. sourceMap: true,
  15. presets: ['env'],
  16. plugins: ['transform-class-properties', 'transform-decorators-legacy', 'transform-object-rest-spread']
  17. },
  18. // 编译插件配置
  19. plugins: [],
  20. // 全局变量设置
  21. defineConstants: {},
  22. // 文件 copy 配置
  23. copy: {
  24. patterns: [
  25. ],
  26. options: {
  27. }
  28. },
  29. // 小程序端专用配置
  30. mini: {
  31. postcss: {
  32. autoprefixer: {
  33. enable: true
  34. },
  35. // 小程序端样式引用本地资源内联配置
  36. url: {
  37. enable: true,
  38. config: {
  39. limit: 10240
  40. }
  41. }
  42. },
  43. // 替换 JSX 中的属性名,参考:
  44. // https://github.com/NervJS/taro/issues/2077
  45. jsxAttributeNameReplace: {}
  46. },
  47. // H5 端专用配置
  48. h5: {
  49. publicPath: '/',
  50. staticDirectory: 'static',
  51. postcss: {
  52. autoprefixer: {
  53. enable: true
  54. }
  55. },
  56. // 自定义 Webpack 配置
  57. webpackChain: {},
  58. devServer: {}
  59. }
  60. };
  61. module.exports = function(merge) {
  62. if (process.env.NODE_ENV === 'development') {
  63. return merge({}, config, require('./dev'));
  64. }
  65. return merge({}, config, require('./prod'));
  66. };