npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-preset-mbp

v0.0.28

Published

babel预设的最佳实践

Downloads

13

Readme

babel-preset-mbp

babel预设的最佳实践

参考来源

  • stage-2/3提案: https://github.com/tc39/proposals
  • stage-1提案: https://github.com/tc39/proposals/blob/master/stage-1-proposals.md
  • stage-0提案: https://github.com/tc39/proposals/blob/master/stage-0-proposals.md
  • 已完成-提案: https://github.com/tc39/proposals/blob/master/finished-proposals.md
  • 不维护-提案: https://github.com/tc39/proposals/blob/master/inactive-proposals.md
  • stage完整: https://github.com/babel/babel/tree/v7.8.5/packages/babel-preset-stage-0
  • stage参考: https://npmjs.com/package/@babel/preset-stage-0
  • preset参考: https://babeljs.io/docs/en/babel-preset-env
  • transform参考: https://babeljs.io/docs/en/babel-plugin-transform-runtime
  • transform-runtime一定配上version参数,减少直接注入代码
  • preset-env内corejs参数,结合useBuiltIns来polyfill对象和方法,相当于import"core-js/es/array"
  • transform-runtime内corejs参数,转换需要polyfill的对象为局部变量,相当于将Promise替换成_Promise

使用方法

  • .babelrc
{ "presets": [["mbp", { "ts": true }]] }

查看依赖

  • 涵盖常用babel依赖,一次引入,随意使用
  • https://npmgraph.js.org/?q=babel-preset-mbp

option

interface Option {
	ts?: boolean | object; // 是否启用ts预设
	vue?: 2 | 3 | { ver: 2 | 3 }; // 是否支持vue版jsx
	react?: boolean | object; // 是否启用react预设
	run?: boolean | object; // 是否启用transform-runtime
	css?: boolean | object; // 是否启用自动识别css_modules
	repl?: boolean | object; // 是否启用引入替换
	[key: string]: any; // env和vue共用配置项
} // 属性值为对象时表示对应语法预设的配置项

开发

  • https://babeljs.io/docs/en/config-files#config-function-api
module.exports = function (_api, _option, _cwd) {
	return { presets: [ ... ], plugins: [ ... ] };
};

变更

  • 新增依赖 babel-plugin-import
  • 新增依赖 babel-plugin-module-resolver
  • 新增依赖 babel-plugin-transform-inline-environment-variables
  • plugins 会运行在 presets 之前
  • plugins 从首个顺序执行
  • presets 从尾个逆序执行
  • 子依赖包内包含的命令不会自动安装,常见使用组合
    • @babel/cli + babel-preset-mbp
    • babel-loader + babel-preset-mbp
    • @rollup/plugin-babel + babel-preset-mbp