All Projects β†’ FlorianRappl β†’ parcel-plugin-externals

FlorianRappl / parcel-plugin-externals

Licence: MIT license
Parcel plugin for declaring externals. These externals will not be bundled. πŸ“¦

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to parcel-plugin-externals

parcel-typescript-react
πŸ“¦ Typescriot react perttier example using parcel bundler
Stars: ✭ 15 (-68.09%)
Mutual labels:  parcel, parcel-bundler
react-redux-boilerplate
A React boilerplate based on Redux, React Router, styled components and Parcel
Stars: ✭ 62 (+31.91%)
Mutual labels:  parcel, parcel-bundler
svelte-box
A truffle box for svelte
Stars: ✭ 60 (+27.66%)
Mutual labels:  parcel, parcel-bundler
parcel-plugin-markdown-string
πŸ“¦@parcel-bundler plugin for loader markdown string, markdown output HTML.
Stars: ✭ 19 (-59.57%)
Mutual labels:  parcel-bundler, parcel-plugin
simplefolio
⚑️ A minimal portfolio template for Developers
Stars: ✭ 10,737 (+22744.68%)
Mutual labels:  parcel, parcel-bundler
parcel-plugin-prerender
No description or website provided.
Stars: ✭ 42 (-10.64%)
Mutual labels:  parcel, parcel-plugin
parcel-react-app
Create React apps using Parcel as build tool.
Stars: ✭ 12 (-74.47%)
Mutual labels:  parcel, parcel-bundler
parcelui
Parcel + Typescript + React/Preact + Router + CSS Modules + SASS + Jest + Api-Now + Github Actions CI
Stars: ✭ 32 (-31.91%)
Mutual labels:  parcel, parcel-bundler
preact-typescript-parcel-starter
Starter with Preact - Typescript - Parcel Bundler
Stars: ✭ 51 (+8.51%)
Mutual labels:  parcel, parcel-bundler
parcel-plugin-url-loader
πŸ“¦url loader for parcel, use base64 encode file
Stars: ✭ 24 (-48.94%)
Mutual labels:  parcel, parcel-plugin
wordpress-starter
Timber (Twig) + Parceljs Bundler
Stars: ✭ 19 (-59.57%)
Mutual labels:  parcel, parcel-bundler
parcel-static-template
Start a simple static site with components and hot reloading.
Stars: ✭ 20 (-57.45%)
Mutual labels:  parcel, parcel-bundler
Gearmanbundle
GearmanBundle for Symfony2
Stars: ✭ 233 (+395.74%)
Mutual labels:  bundle
yavdb
Yet Another Vulnerability Database
Stars: ✭ 14 (-70.21%)
Mutual labels:  dependencies
Fmelfinderbundle
πŸ“ ElFinderBundle provides ElFinder integration with TinyMCE, CKEditor, Summernote editors
Stars: ✭ 231 (+391.49%)
Mutual labels:  bundle
Minipack Explain
explain: <minipack> simple bundle 捆绑器 η€ΊδΎ‹ γ€ŒηΏ»θ―‘γ€β€οΈ ζ ‘ε―Ή βœ…
Stars: ✭ 229 (+387.23%)
Mutual labels:  bundle
SonataTimelineBundle
[Abandoned] Integrates SpyTimelineBundle into Sonata
Stars: ✭ 24 (-48.94%)
Mutual labels:  bundle
bandmaster
Simple and easily extendable Go library for managing runtime services & dependencies (datastores, APIs, MQs, custom...).
Stars: ✭ 43 (-8.51%)
Mutual labels:  dependencies
Victoire
Fullstack Symfony CMS: The perfect mix between a framework and a CMS
Stars: ✭ 227 (+382.98%)
Mutual labels:  bundle
Oauth2 Bundle
Symfony bundle which provides OAuth 2.0 authorization/resource server capabilities.
Stars: ✭ 215 (+357.45%)
Mutual labels:  bundle

parcel-plugin-externals

Build Status npm GitHub tag GitHub issues

Parcel plugin for declaring externals. These externals will not be bundled. πŸ“¦

Usage

As with any other Parcel plugin you should make sure to have the Parcel bundler installed and the plugin referenced from the package.json of your project.

The package.json has to be changed to either contain peerDependencies or externals. The latter is more flexible.

Use Global Require

Consider the following snippet (from package.json):

{
  "peerDependencies": {
    "react": "*"
  }
}

This plugin will omit React from your bundle. Instead, a call to require('react') will be left over. If the global require inserted by Parcel does not know how to resolve it you will face an error.

Alternatively, you could have also written the following snippet (from package.json):

{
  "externals": [
    "react"
  ]
}

Use Global Variable

Potentially, instead you want to hint Parcel that you already have a global available coming from another script. The externals definition can help you.

Consider the following snippet (from package.json):

{
  "externals": {
    "react": "React"
  }
}

Here we tell the plugin to alias the react module with React. In this case we reference a global variable React, which obviously must exist.

Note: Don't confuse this with the abilities coming from parcel-plugin-html-externals. Values that are non-string instances will be ignored. So you can actually use both plugins, parcel-plugin-externals and parcel-plugin-html-externals if you want to (or just one of the two).

Use Custom Locations

The object syntax is a shorthand for combining the keys and values for a replacement expression. The snippet above is acutally equalivant to:

{
  "externals": [
    "react => React"
  ]
}

Expressions could be more complex:

{
  "externals": [
    "react => window.dependencies.React"
  ]
}

In this case dependencies must exist globally with React being one of its properties.

Alternatively, you could forward one module to another with require:

{
  "externals": [
    "react => require('preact')"
  ]
}

Important: This is an early version of the plugin. Please give feedback on GitHub, especially regarding configuration and syntax. The idea is to keep the plugin simple and the options straight and to the point.

Dynamic Dependency Resolution

Sometimes you want to externalize a whole set of dependencies, potentially by a given rule, e.g., react-* or similar. For such cases you can also refer to a module that does the replacement rule determination:

{
  "externals": "./tools/ruleFactory.js"
}

The rule factory module is just a simple Node.js module that exports a function:

const rx = /react-(.*?)\//;

module.exports = function(path) {
  const result = rx.exec(path);

  if (result) {
    const suffix = result[1];
    const name = suffix[0].toUpperCase() + suffix.substr(1);
    return `react-${suffix} => React${name}`;
  }

  return undefined;
};

What you need to return is either undefined (i.e., the module will not be externalized) or the replacement rule.

Remark: If the rule does not contain the forward => slash it will be interpreted as returnValue => require('returnValue'), where returnValue is the part returned from the function.

Virtual Modules

By default, the modules must be present in the local installation. Otherwise Parcel will complain. This is not always possible / the case.

In this scenario you'll need a virtual module. You can get support for this via Parcel's standard alias.

Consider the following snippet (from package.json):

{
  "externals": [
    "react",
    "foo"
  ],
  "alias": {
    "foo": "./src/foo-virtual.js"
  }
}

Here, we will identify that foo is an external alias and still externalize the call (in the given example to use require('foo')). You could leave the virtual module empty.

Important: If you have multiple virtual modules you should give them all unique paths. Otherwise, this plugin cannot distinguish between them.

Specialized Control

If you need further fine-grained control (e.g., for switching between development and production builds) you can just use the factory function introduced above.

To simplify you can also use the factory module to export the array directly.

const isProduction = process.env.NODE_ENV === 'production';
module.exports = isProduction ? [
  'my-dep',
  'react'
] : [
  'my-dep'
];

This way you can get flexibility without sacrificing convenience.

Changelog

This project adheres to semantic versioning.

You can find the changelog in the CHANGELOG.md file.

License

This plugin is released using the MIT license. For more information see the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].