browserify-optional

WebJar for browserify-optional

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

browserify-optional
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

browserify-optional
WebJar for browserify-optional
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/devongovett/browserify-optional

Download browserify-optional

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/browserify-optional/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>browserify-optional</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/browserify-optional/
implementation 'org.webjars.npm:browserify-optional:1.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/browserify-optional/
implementation ("org.webjars.npm:browserify-optional:1.0.1")
'org.webjars.npm:browserify-optional:jar:1.0.1'
<dependency org="org.webjars.npm" name="browserify-optional" rev="1.0.1">
  <artifact name="browserify-optional" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='browserify-optional', version='1.0.1')
)
libraryDependencies += "org.webjars.npm" % "browserify-optional" % "1.0.1"
[org.webjars.npm/browserify-optional "1.0.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.npm : ast-transform jar [0.0.0]
org.webjars.npm : ast-types jar [0.7.0,0.8)
org.webjars.npm : browser-resolve jar [1.8.1,2)

Project Modules

There are no modules declared in this project.

browserify-optional

It is a common pattern in Node to support optional dependencies via requires in try..catch blocks. Browserify doesn't support this by default and throws a compile time error when it cannot find a module. You can solve the problem by using browserify's exclude option, but this works globally instead of at a per-module level. This transform fixes the problem by moving the compile time error to a runtime error for requires of missing modules inside try..catch blocks.

Example

The transform would transform the following code such that requiring missing-module would throw a runtime error instead of a compile time error, making the code work as expected.

try {
  var x = require('missing-module');
} catch (e) {
  var x = require('replacement-module');
}

To set it up in browserify, add this to your package.json:

"browserify": {
  "transform": ["browserify-optional"]
}

License

MIT

Versions

Version
1.0.1