Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: resolve main reference to other modules #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Whenever another module ```requires``` your module by name, the bundler will loa

All paths for browser fields are relative to the ```package.json``` file location (and usually project root as a result).

The replacement is resolved similar to how `require` works, so you can replace with a specific file or also another module:

```javascript
"browser": "some-shim"
```

### replace specific files - advanced

In many cases, there is a large amount of code which is applicable to both client and server. If is easier to just replace some files instead of creating a completely new entry point. To do this, just specify an object versus a single string.
Expand All @@ -59,6 +65,15 @@ Now when you package your code, uses of ```module-a``` will be replaced with cod

If a module you depend on already includes a ```browser``` field, then you don't have to do anything special. Whenever you require that module, the bundler SHOULD use the hint provided by the module.

The replacement is resolved similar to how `require` works, so you can replace with a specific file or also another module:

```javascript
"browser": {
"module-a": "foo",
"./server/only.js": "bar"
}
```

### ignore a module
You can simply prevent a module or file from being loaded into a bundle by specifying a value of ```false``` for any of the keys. This is useful if you know certain codepaths will not be executed client side but find it awkward to split up or change the code structure.

Expand All @@ -74,6 +89,13 @@ The above will cause the following to return an empty object into `a`.
var a = require('module-a');
```

Sometimes an empty object is not the most convenient value. For example, if normally a function is expected, it may be preferable to replace with an empty function rather than empty object. In that case, you could specify to replace with the `noop` or `identity` function:

```javascript
"browser": "utilise.identity"
"browser": "utilise.noop"
```

Note: The use of `false` should be restricted to only the most essential places in your app code where other browser field approaches do not work. It is discouraged but sometimes a necessary approach to blacklist a module from client packaging.

## Advantages
Expand Down