Coder Social home page Coder Social logo

webpack-proxy's Introduction

webpack-proxy

NPM version NPM downloads CircleCI donate chat

preview

Install

yarn add webpack-proxy

Usage

Let's say you want to use buble-loader, you can just add it to your webpack config without installing buble-loader and buble, since webpack-proxy will handle that for you!

๐Ÿ“ webpack.config.js:

const proxy = require('webpack-proxy')

module.exports = {
  entry: './index.js',
  module: {
    rules: [
      {
        test: /\.js$/,
        use: proxy({
          loader: 'buble-loader',
          options: {
            // ...loader options
          }
        })
      }
    ]
  }
}

How does it work?

In:

proxy(yourLoader, options)

Out:

[
  {
    loader: require.resolve('webpack-proxy/lib/proxy-loader'),
    options: yourLoader
  },
  {
    loader: require.resolve('webpack-proxy/lib/ensure-loader'),
    options: {
      loader: yourLoader.loader,
      version: options.version,
      dependencies: options.dependencies,
      peerFilter: options.peerFilter
    }
  }
]

ensure-loader is used to install missing dependencies, proxy-loader is used to run your loader.

webpack itself will check if your loader exists before compiling, but we want to handle this ourselves via ensure-loader, which is why we use proxy-loader here.

API

proxy(UseEntry, [options])

Return an array of UseEntry.

options

version

Type: string

Set the version range of the missing loader to install.

dependencies

Type: string[]

Add extra dependencies to install alongside your loader. e.g. for sass-loader you need to add node-sass to dependencies since it's not listed as peerDependencies of sass-loader.

peerFilter

Type: (depName: string, version: string) => boolean

Filter peer dependencies, return true to include, false otherwise.

proxy.chain(Rule, UseEntry, [options])

Add UseEntry to certain webpack-chain rule.

Credits

Heavily inspired by Parcel bundler and preact-cli.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

webpack-proxy ยฉ egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

github.com/egoist ยท GitHub @egoist ยท Twitter @_egoistlily

webpack-proxy's People

Contributors

egoist avatar

Stargazers

Andrew Chou avatar Sergey Bezrukov avatar Rubens F. avatar Fernando Daciuk avatar Pedro Nauck avatar Vincent avatar chenn avatar Rhy Moore avatar Megas Liu avatar Gregg B avatar Andy Parsons avatar Maher Saif avatar Takuya Fukuju avatar Evgenii Karagodin avatar Ramon Schmidt Rocha avatar Myroslav Kiurchev avatar Jesus Manuel Olivas avatar Roman Minchyn avatar Patrick Lienau avatar Vlad Trukhin avatar Mirza Pasic avatar Denis Denisov avatar Thomas Deinhamer avatar ๅด่ƒ่ƒ avatar Leo sun avatar Seth Bertalotto avatar Robin van der Vleuten avatar Matija Grcic avatar Gosha Spark avatar Tom Bonnike avatar Asaf Katz avatar Josh Black avatar Hiroki Yamamoto avatar toru hamaguchi avatar Olivier Ligot avatar Lucas Lentz avatar GongChao avatar  avatar Newman avatar Javier Diaz avatar Huy Giang avatar

Watchers

James Cloos avatar aurimas avatar  avatar  avatar

webpack-proxy's Issues

Support webpack-chain

const jsRule = config.module.rule('js').test(/\.js$/)

proxy.chain(jsRule, {
  loader: 'babel-loader',
  options: {}
})

Manually specify dependencies to install

e.g. node-sass is not listed in sass-loader's peerDependencies but currently it's required..

proxy({
  loader: 'sass-loader'
}, {
  devDependencies: ['node-sass']
})

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.