Giter Club home page Giter Club logo

babel-preset-miniprogram's Introduction

babel-preset-miniprogram

微信小程序 babel 构建环境预设

安装

npm install --save-dev babel-preset-miniprogram

使用

// babel.config.js
module.exports = {
  presets: [
    [
      'babel-preset-miniprogram',
      {
        wechatLibVersion: '2.14.0', // 指定小程序最低基础库版本
        useBuiltIns: 'usage', // 打入 Polyfill
        modules: 'cjs', // 将代码转义为 commonjs
      },
    ],
  ],
};

配置项

wechatLibVersion: string

指定构建小程序的目标最低基础库版本,可以在 小程序管理页 【设置】-【基本设置】-【基础库最低版本设置】中设置你的小程序最低版本

其余配置项可直接使用 @babel/preset-env配置项

实现

由于小程序基础库版本会与小程序运行环境版本绑定,因此特定小程序基础库可能的运行环境是确定的。 该预设便是利用该信息,只将运行环境必要的转义和 Polyfill 设置给 @babel/preset-env,从而尽可能减少编译处理和小程序代码体积。

另外由于小程序基础库本身自带了一个 Polyfill,该预设也会避免打入不必要的 Polyfill。

babel-preset-miniprogram's People

Contributors

tidyzq avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.