Skip to content

Commit

Permalink
feat: allow configuring the top level this value (#1219)
Browse files Browse the repository at this point in the history
* feat: allow configuring the top level `this` value

* refactor: address review comments
  • Loading branch information
fubhy authored Oct 6, 2020
1 parent 9c47b41 commit 30dfc5c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/docs/10-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Options:
- Snowpack uses Rollup internally to install your packages. This `rollup` config option gives you deeper control over the internal rollup configuration that we use.
- **`installOptions.rollup.plugins`** - Specify [Custom Rollup plugins](#installing-non-js-packages) if you are dealing with non-standard files.
- **`installOptions.rollup.dedupe`** - If needed, deduplicate multiple versions/copies of a packages to a single one. This helps prevent issues with some packages when multiple versions are installed from your node_modules tree. See [rollup-plugin-node-resolve](https://github.com/rollup/plugins/tree/master/packages/node-resolve#usage) for more documentation.
- **`installOptions.rollup.context`** - Specify top-level `this` value. Useful to silence install errors caused by legacy common.js packages that reference a top-level this variable, which does not exist in a pure ESM environment.

#### `config.devOptions`

Expand Down
2 changes: 2 additions & 0 deletions esinstall/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ interface InstallOptions {
externalPackage: string[];
namedExports: string[];
rollup: {
context?: string;
plugins?: RollupPlugin[]; // for simplicity, only Rollup plugins are supported for now
dedupe?: string[];
};
Expand Down Expand Up @@ -351,6 +352,7 @@ ${colors.dim(
let isFatalWarningFound = false;
const inputOptions: InputOptions = {
input: installEntrypoints,
context: userDefinedRollup.context,
external: (id) => externalPackages.some((packageName) => isImportOfPackage(id, packageName)),
treeshake: {moduleSideEffects: 'no-external'},
plugins: [
Expand Down
1 change: 1 addition & 0 deletions snowpack/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const configSchema = {
rollup: {
type: 'object',
properties: {
context: {type: 'string'},
plugins: {type: 'array', items: {type: 'object'}},
dedupe: {
type: 'array',
Expand Down

1 comment on commit 30dfc5c

@vercel
Copy link

@vercel vercel bot commented on 30dfc5c Oct 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.