編譯配置

2020-05-12 17:47 更新

編譯配置存放于項(xiàng)目根目錄下 config 目錄中,包含三個(gè)文件

  • index.js 是通用配置
  • dev.js 是項(xiàng)目預(yù)覽時(shí)的配置
  • prod.js 是項(xiàng)目打包時(shí)的配置

index.js —— 通用配置

const config = {
  // 項(xiàng)目名稱
  projectName: 'kj',
  // 項(xiàng)目創(chuàng)建日期
  date: '2018-6-8',
  // 設(shè)計(jì)稿尺寸
  designWidth: 750,
  // 項(xiàng)目源碼目錄
  sourceRoot: 'src',
  // 項(xiàng)目產(chǎn)出目錄
  outputRoot: 'dist',
  // babel 編譯配置
  babel: {
    sourceMap: true,
    presets: ['env'],
    plugins: ['transform-class-properties', 'transform-decorators-legacy', 'transform-object-rest-spread']
  },
  // 編譯插件配置
  plugins: [],
  // 全局變量設(shè)置
  defineConstants: {},
  // 文件 copy 配置
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  // 小程序端專用配置
  mini: {
    postcss: {
      autoprefixer: {
        enable: true
      },
      // 小程序端樣式引用本地資源內(nèi)聯(lián)配置
      url: {
        enable: true,
        config: {
          limit: 10240
        }
      }
    },
    // 替換 JSX 中的屬性名,參考:
    // https://github.com/NervJS/taro/issues/2077
    jsxAttributeNameReplace: {}
  },
  // H5 端專用配置
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    postcss: {
      autoprefixer: {
        enable: true
      }
    },
    // 自定義 Webpack 配置
    webpackChain: {},
    devServer: {}
  }
};

module.exports = function(merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'));
  }
  return merge({}, config, require('./prod'));
};


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號