S

Sapling

V1

2022/09/08阅读:27主题:科技蓝

taro编译配置

Taro编译配置

taro的编译配置存放在项目根目录下的config文件中,有三个文件

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

1. 默认配置

// config/index.js

const config = {
  // 项目名称
  projectName'Awesome Next',
  // 项目创建日期
  date'2020-6-2',
  // 设计稿尺寸
  designWidth750,
  // 设计稿尺寸换算规则
  deviceRatio: {
    6402.34 / 2,
    7501,
    8281.81 / 2
  },
  // 项目源码目录
  sourceRoot'src',
  // 项目产出目录
  outputRoot'dist',
  // Taro 插件配置
  plugins: [],
  // 全局变量设置
  defineConstants: {},
  // 文件 copy 配置
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  // 框架,react,nerv,vue, vue3 等
  framework'react',
  // 小程序端专用配置
  mini: {
    postcss: {
      autoprefixer: {
        enabletrue
      },
      // 小程序端样式引用本地资源内联配置
      url: {
        enabletrue,
        config: {
          limit10240
        }
      },
      cssModules: {
        enablefalse// 默认为 false,如需使用 css modules 功能,则设为 true
        config: {
          namingPattern'module'// 转换模式,取值为 global/module
          generateScopedName'[name]__[local]___[hash:base64:5]'
        }
      }
    },
    // 自定义 Webpack 配置
    webpackChain (chain, webpack) {}
  },
  // H5 端专用配置
  h5: {
    publicPath'/',
    staticDirectory'static',
    postcss: {
      autoprefixer: {
        enabletrue
      },
      cssModules: {
        enablefalse// 默认为 false,如需使用 css modules 功能,则设为 true
        config: {
          namingPattern'module'// 转换模式,取值为 global/module
          generateScopedName'[name]__[local]___[hash:base64:5]'
        }
      }
    },
    // 自定义 Webpack 配置
    webpackChain (chain, webpack) {},
    devServer: {}
  }
};

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

2. 配置详情

  • sourceRoot 源代码存在的目录

类型:string 默认:src

  • outputRoot 打包后的代码存在目录

类型:string 默认:dist

  • designWidth 设计稿尺寸

类型:numberfunction

默认值:750

分类:

后端

标签:

后端

作者介绍

S
Sapling
V1