Skip to content

Option to apply transforms to third-party node_modules #2013

@taylorjdawson

Description

@taylorjdawson

🙋 feature request

One feature that is seriously lacking is the ability to apply transforms to third-party node_modules. As previously stated:

This even works in third-party node_modules: if a configuration file is published as part of the package, the transform is automatically turned on for that module only.
Parcel Docs

It seems as if Parcel has the ability but not the option to achieve this. The issue has been discussed before, however, it did not apply to third-party node_modules.
It seems that I am not alone... (& also)

🤔 Expected Behavior

If specified, Parcel will apply transforms on the third party node_modules before bundling.

😯 Current Behavior

Right now Parcel is unable to recognize the object spread operator in third-party node_modules because Parcel does not transform the third party node_module before bundling. Thus, when importing third party node_modules that do not have a .babelrc & they use the ...(obj) operator then the build will fail:

🚨  ../node_modules/ky/index.js:21:19: Unexpected token (21:19)
  19 |                          }
  20 |
> 21 |                          returnValue = {...returnValue, [key]: value};
     |                                         ^
  22 |                  }
  23 |          }
  24 |  }

💁 Possible Solution

CLI:
parcel build index.js --include <3rd party module>
API:

// Bundler options
const options = {
  transforms: [
    'node_module_a',
    'node_module_b',
  ]
}

Apply to all external modules:

let ext_modules = Object.keys(require('./package.json').dependencies)
// Bundler options
const options = {
  transforms: ext_modules
}

🔦 Context

I am trying to use Parcel to build for node and browser.

💻 Examples

If a dev could point me in the right direction I could begin implementation immediately. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions