Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Update README.md with note on symlinks (#405)
Browse files Browse the repository at this point in the history
* Update README.md with note on symlinks

This addresses the confusion reported in #402 

IMO it would be nice to make this easier on people by supporting includeModule/excludeModule, but in the meantime we should document symlinks a bit better.

* Couple cleanups

* Apply suggestions from code review

Co-Authored-By: Andrew Powell <shellscape@users.noreply.github.com>

* Update namedExports docs

Prefer specifying module names over paths
  • Loading branch information
bterlson authored and lukastaegert committed Aug 22, 2019
1 parent de40daa commit e431c29
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Expand Up @@ -54,7 +54,7 @@ export default {

// explicitly specify unresolvable named exports
// (see below for more details)
namedExports: { './module.js': ['foo', 'bar' ] }, // Default: undefined
namedExports: { 'react': ['createElement', 'Component' ] }, // Default: undefined

// sometimes you have to leave require statements
// unconverted. Pass an array containing the IDs
Expand All @@ -66,16 +66,18 @@ export default {
};
```

### Usage in monorepo
### Usage with symlinks

In case you are using a monorepo, you may want to use a regular expression for `include` as the string 'node_modules' will not match if your `node_modules` is not in your current working directory (i.e. '../node_modules'). Try this:
Symlinks are common in monorepos and are also created by the `npm link` command. Rollup with `rollup-plugin-node-resolve` resolves modules to their real paths by default. So `include` and `exclude` paths should handle real paths rather than symlinked paths (e.g. `../common/node_modules/**` instead of `node_modules/**`). You may also use a regular expression for `include` that works regardless of base path. Try this:

```
commonjs({
include: /node_modules/
})
```

Whether symlinked module paths are [realpathed](http://man7.org/linux/man-pages/man3/realpath.3.html) or preserved depends on Rollup's `preserveSymlinks` setting, which is false by default, matching Node.js' default behavior. Setting `preserveSymlinks` to true in your Rollup config will cause `import` and `export` to match based on symlinked paths instead.

### Custom named exports

This plugin will attempt to create named exports, where appropriate, so you can do this...
Expand Down Expand Up @@ -107,7 +109,7 @@ commonjs({
// left-hand side can be an absolute path, a path
// relative to the current directory, or the name
// of a module in node_modules
'node_modules/my-lib/index.js': [ 'named' ]
'my-lib': [ 'named' ]
}
})
```
Expand Down

0 comments on commit e431c29

Please sign in to comment.