Giter VIP home page Giter VIP logo

esbuild-plugin-browserslist's Introduction

esbuild-plugin-browserslist

build status

Configure esbuild's target based on a browserslist query

Installation

yarn add esbuild-plugin-browserslist esbuild browserslist

Usage

import esbuild from "esbuild";
import browserslist from "browserslist";
import {
  esbuildPluginBrowserslist,
  resolveToEsbuildTarget,
} from "esbuild-plugin-browserslist";

await esbuild.build({
  entryPoints: ["./foo/bar.ts"],
  // ... other options (except `target`) ...
  plugins: [
    esbuildPluginBrowserslist(browserslist("defaults"), {
      printUnknownTargets: false,
    }),
  ],
});

// Or:

const target = resolveToEsbuildTarget(browserslist("defaults"), {
  printUnknownTargets: false,
});

await esbuild.build({
  entryPoints: ["./foo/bar.ts"],
  target,
});
ℹī¸ CJS usage instructions

Adjust the imports as follows:

const esbuild = require("esbuild");
const browserslist = require("browserslist");
const {
  esbuildPluginBrowserslist,
  resolveToEsbuildTarget,
} = require("esbuild-plugin-browserslist");

Caveats

  • Only edge, firefox, chrome, safari, ios_saf, and node have direct equivalents for esbuild targets.
  • android and and_chr are mapped to the chrome target, and and_ff is mapped to the firefox target.
  • All other browsers are ignored (and_qq, samsung, opera, op_mini, op_mob, ie, ie_mob, bb, baidu, and kaios)

Debugging

You can turn on debug logs (which will print all resolutions or failures) using DEBUG=esbuild-plugin-browserslist

esbuild-plugin-browserslist's People

Contributors

actions-user avatar dependabot[bot] avatar github-actions[bot] avatar jfsiii avatar m-51 avatar nihalgonsalves avatar plmrry avatar rmehner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

esbuild-plugin-browserslist's Issues

allow newer versions of esbuild

Attempting to use this plugin with newer versions of esbuild (v0.14) throws a package version error during install.

Could the package's version of esbuild be set to allow newer versions: ^0.13.0 instead of ~0.13.0?

"esbuild": "~0.13.8",

If not, could the esbuild version used in this package be bumped to v0.14?

Could not parse Browserslist result to a meaningful format. entry=safari TP

The following browserslist query:

  "last 3 Chrome major versions",
  "last 3 Safari major versions",
  "unreleased Chrome versions",
  "unreleased Safari versions"

Resolves to include:

...
safari TP

Which then is logged by esbuild-plugin-browserslist:

Could not parse Browserslist result to a meaningful format. entry=safari TP

The equivalent browsers for chrome do not cause esbuild-plugin-browserslist to emit such a log.

I believe that esbuild-plugin-browserslist should be updated to resolve this browser version into an esbuild target.

Thanks!

Not working

'use strict'

const browserslist = require('browserslist')
const {
  resolveToEsbuildTarget
} = require('esbuild-plugin-browserslist')

const target = resolveToEsbuildTarget(
  browserslist('default', {
    printUnknownTargets: false
  })
)

console.log(target)
C:\wamp64\www\AdminLTE-ts\node_modules\browserslist\index.js:1179
        throw unknownQuery(name)
        ^
Error [BrowserslistError]: Unknown browser query `default`. Maybe you are using old Browserslist or made typo in query.
    at unknownQuery (C:\wamp64\www\AdminLTE-ts\node_modules\browserslist\index.js:285:10)
    at Function.select (C:\wamp64\www\AdminLTE-ts\node_modules\browserslist\index.js:1179:15)
    at C:\wamp64\www\AdminLTE-ts\node_modules\browserslist\index.js:336:33
    at Array.reduce (<anonymous>)
    at resolve (C:\wamp64\www\AdminLTE-ts\node_modules\browserslist\index.js:318:18)
    at browserslist (C:\wamp64\www\AdminLTE-ts\node_modules\browserslist\index.js:444:21)
    at Object.<anonymous> (C:\wamp64\www\AdminLTE-ts\build\config\esbuild.config.js:9:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32) {
  browserslist: true
}

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.