From 5a0aa6f957e6c86a4eb8f0180fa366732453eb25 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Tue, 20 Aug 2019 11:01:48 -0700 Subject: [PATCH 1/4] 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. --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3502ccc..d829207 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,9 @@ 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 command `npm link`. Rollup with rollup-plugin-node-resolve resolves modules to their real paths by default. So include and exclude paths should handle real paths not 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({ @@ -76,6 +76,8 @@ commonjs({ }) ``` +Whether symlinked module paths are realpathed or preserved depends on Rollup's preserveSymlinks setting. It is false by default, matching Node's default behavior. Setting preserveSymlinks to true in your Rollup config will cause import and export to match based on symlinked paths. + ### Custom named exports This plugin will attempt to create named exports, where appropriate, so you can do this... From 0eaa820ce4e472db1ab7fcd8394b7e30b2482e49 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Tue, 20 Aug 2019 11:05:19 -0700 Subject: [PATCH 2/4] Couple cleanups --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d829207..0ae979a 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ export default { }; ``` -### Usage with Symlinks +### Usage with symlinks Symlinks are common in monorepos and are also created by the command `npm link`. Rollup with rollup-plugin-node-resolve resolves modules to their real paths by default. So include and exclude paths should handle real paths not 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: @@ -76,7 +76,7 @@ commonjs({ }) ``` -Whether symlinked module paths are realpathed or preserved depends on Rollup's preserveSymlinks setting. It is false by default, matching Node's default behavior. Setting preserveSymlinks to true in your Rollup config will cause import and export to match based on symlinked paths. +Whether symlinked module paths are realpathed or preserved depends on Rollup's preserveSymlinks setting. It is false by default, matching Node's 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 From 534dabec30c1c28990ec156653f9ca18778dab15 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Tue, 20 Aug 2019 11:27:03 -0700 Subject: [PATCH 3/4] Apply suggestions from code review Co-Authored-By: Andrew Powell --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0ae979a..b8feb45 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ export default { ### Usage with symlinks -Symlinks are common in monorepos and are also created by the command `npm link`. Rollup with rollup-plugin-node-resolve resolves modules to their real paths by default. So include and exclude paths should handle real paths not 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: +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({ @@ -76,7 +76,7 @@ commonjs({ }) ``` -Whether symlinked module paths are realpathed or preserved depends on Rollup's preserveSymlinks setting. It is false by default, matching Node's default behavior. Setting preserveSymlinks to true in your Rollup config will cause import and export to match based on symlinked paths instead. +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 From 7269645197f3757db76165af64277bd305c10755 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Wed, 21 Aug 2019 18:34:56 -0700 Subject: [PATCH 4/4] Update namedExports docs Prefer specifying module names over paths --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b8feb45..7f356a1 100644 --- a/README.md +++ b/README.md @@ -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 @@ -109,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' ] } }) ```