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-webpack-test

v1.0.0

Published

- Babel 默认只转换新的 JavaScript 句法(syntax) - 不转换新的 API,比如 Iterator、Generator、Set、Maps、Proxy、Reflect、Symbol、Promise 等全局对象,以及一些定义在全局对象上的方法(比如 Object.assign)都不会转码。 - 不转换实例方法(例如 Array.prototype.includes 等) - 如果想让这个方法运行,必须使用 Polyfill 或 Babel-runtime,为当前环境提供一个垫片。

Downloads

1

Readme

babel:

  • Babel 默认只转换新的 JavaScript 句法(syntax)
  • 不转换新的 API,比如 Iterator、Generator、Set、Maps、Proxy、Reflect、Symbol、Promise 等全局对象,以及一些定义在全局对象上的方法(比如 Object.assign)都不会转码。
  • 不转换实例方法(例如 Array.prototype.includes 等)
  • 如果想让这个方法运行,必须使用 Polyfill 或 Babel-runtime,为当前环境提供一个垫片。

@babel/preset-env

一系列同类插件组合,配合 useBuiltIns 参数、自动引入 polyfill 垫片处理新的 API 以及实例方法

缺点:我们使用 polyfill 的方式引入了内置函数、比如 Promise,会污染全局。

//默认配置
{
  targets:{},//需要支持的目标浏览器,不配置默认全部转成 ES5
  spec:false,
  loose:false,
  modules:'auto',//webpack 会将 es6 转成 commonjs 规范,babel 就不要转了,一般配置成 false
  debug:false,
  include:[],
  exclude:[],
  useBuiltIns:false,// false:不使用垫片| entry:一股脑引入所有垫片,体积太大 | usage:按需导入
  corejs:2,//polyfill 垫片,3 是最新的版本
  forceAllTransforms:false,
  configPath:process.cwd(),//当前目录
  ignoreBrowserslistConfig:false,
  shippedProposals:false
}

@babel/runtime

  • 开发类库/工具(生成不污染全局空间和内置对象原型的代码)
  • 借助 @babel/runtime 中帮助函数(helper function)移除冗余工具函数
//默认配置
{
  absoluteRuntime: false,//配置 @babel/runtime模块路径,默认从node_modules读取
  corejs: false,//false:使用preset-env的corejs,但是会存在污染全局问题(如:Array.from),设置2/3会覆盖preset-env的corejs,且不会污染全局
  helpers: true,//开启帮助函数,移除冗余工具函数
  regenerator: true,//通过 preset-env 已经使用了全局的 regeneratorRuntime, 不再需要 transform-runtime 提供的 不污染全局的 regeneratorRuntime 可以设置为false
  useESModules: false// 是否使用 es modules helpers, 减少 commonJS 语法代码,而且webpack 会将 es6 转成 commonjs 规
}

总结

  1. 项目开发中使用
//.babelrc.js
const config = {
  presets: [
    [
      "@babel/env",
      {
        targets: {
          edge: "17",
          firefox: "60",
          chrome: "44",
          safari: "7"
        },
        useBuiltIns: "usage",
        corejs: 3,
        modules: false
      }
    ]
  ],
  plugins: [
    [
      "@babel/plugin-transform-runtime",
      {
        helpers: true,
        regenerator: false,
        useESModules: true
      }
    ]
  ]
};
  1. 开发工具类库使用
//.babelrc.js

const config = {
  presets: [
    [
      "@babel/env",
      {
        targets: {
          edge: "17",
          firefox: "60",
          chrome: "44",
          safari: "7"
        },
        useBuiltIns: "usage",
        corejs: 3,
        modules: false
      }
    ]
  ],
  plugins: [
    [
      "@babel/plugin-transform-runtime",
      {
        corejs: 3,
        helpers: true,
        regenerator: true,
        useESModules: true
      }
    ]
  ]
};
module.exports = config;

DEMO

npm run webpack
npm run babel