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-cv

v0.2.0

Published

Common babel preset

Downloads

4

Readme

babel-preset-cv

安装

yarn add babel-preset-cv -D

使用

babel.config.js 文件内加上

{
	"preset": ["cv"]
}

默认配置

{
	"presets": [
		["@babel/preset-env", { useBuiltIns: 'entry', corejs: 3 }],
		"@babel/preset-typescript",
		"@babel/preset-react"
	],
	"plugins": [
		"@babel/plugin-syntax-dynamic-import",
		"@babel/plugin-proposal-optional-chaining",
		"@babel/plugin-proposal-object-rest-spread",
		["@babel/plugin-proposal-decorators", { "legacy": true }],
		["@babel/plugin-proposal-class-properties", { "loose": true }],
		["@babel/plugin-proposal-private-property-in-object", { "loose": true }],
		["@babel/plugin-proposal-private-methods", { "loose": true }],
		["@babel/plugin-transform-runtime", { "corejs": 3 }],
	]
}

参数配置

  • typescript - 使用 @babel/preset-typescript ,默认开启。 若想取消该配置:

    {
    	"preset": [{ "cv", { "typescript": false } }]
    }
  • react - 使用 @babel/preset-react ,默认开启。 若想取消该配置:

    {
    	"preset": [{ "cv", { "react": false } }]
    }
  • envOpt - 改变 @babel/preset-env 的参数,默认配置将被覆盖 :

    {
    	"preset": [{ "cv", { "envOpt": { target: 'node' } } }]
    }
  • runtimeOpt - 改变 @babel/plugin-transform-runtime 的参数,默认配置将被覆盖:

    {
    	"preset": [{ "cv", { "runtimeOpt": { "corejs" : 2 } } }]
    }

覆盖配置

若参数配置无法满足条件,可直接基于默认配置内的包编写自己的 babel.config.js

如何选择配置

配置区别

App: If you are authoring an app, use import 'core-js at the top of your app with useBuiltIns set to entry and @babel/transform-runtime only for helpers (@babel/runtime as dependency). This way you pollute the global environment but you don't care, its your app. You will have the benefit of helpers aliased to @babel/runtime and polyfills included at the top of your app. This way you also don't need to process node_modules (except when a dependency uses a syntax that has to be transpiled) because if some dependency used a feature that needs a polyfill, you already included that polyfill at the top of your app.

Library: If you are authoring a library, use only @babel/transform-runtime with corejs option plus @babel/runtime-corejs3 as dependency, and @babel/preset-env for syntax transpilation with useBuiltIns: false. Also I would transpile packages I would use from node_modules. For this you will need to set the absoluteRuntime option (https://babeljs.io/docs/en/babel-plugin-transform-runtime#absoluteruntime) to resolve the runtime dependency from a single place, because @babel/transform-runtime imports from @babel/runtime-corejs3 directly, but that only works if @babel/runtime-corejs3 is in the node_modules of the file that is being compiled.