parcel-plugin-externals
Advanced tools
Comparing version 0.1.0 to 0.2.0-pre.20191021.1
# parcel-plugin-externals Changelog | ||
## 0.2.0 | ||
- Allow `externals` definition via object (#1) | ||
## 0.1.0 | ||
- Initial release |
{ | ||
"name": "parcel-plugin-externals", | ||
"version": "0.1.0", | ||
"version": "0.2.0-pre.20191021.1", | ||
"description": "A plugin for Parcel to omit declared externals from being included in the emitted bundles.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# parcel-plugin-externals | ||
[![Build Status](https://florianrappl.visualstudio.com/parcel-plugin-externals/_apis/build/status/FlorianRappl.parcel-plugin-externals?branchName=master)](https://florianrappl.visualstudio.com/parcel-plugin-externals/_build/latest?definitionId=12&branchName=master) | ||
[![Build Status](https://florianrappl.visualstudio.com/parcel-plugin-externals/_apis/build/status/FlorianRappl.parcel-plugin-externals?branchName=master)](https://florianrappl.visualstudio.com/parcel-plugin-externals/_build/latest?definitionId=14&branchName=master) | ||
[![npm](https://img.shields.io/npm/v/parcel-plugin-externals.svg)](https://www.npmjs.com/package/parcel-plugin-externals) | ||
@@ -34,2 +34,14 @@ [![GitHub tag](https://img.shields.io/github/tag/FlorianRappl/parcel-plugin-externals.svg)](https://github.com/FlorianRappl/parcel-plugin-externals/releases) | ||
{ | ||
"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. | ||
The object syntax is a shorthand for combining the keys and values for a replacement expression. The snippet above is acutally equalivant to: | ||
```json | ||
{ | ||
"externals": [ | ||
@@ -41,3 +53,3 @@ "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. Expressions could be more complex: | ||
Expressions could be more complex: | ||
@@ -64,3 +76,3 @@ ```json | ||
**Important**: This is an early version of the plugin. Please give feedback, especially regarding configuration and syntax. The idea is to keep the plugin simple and the options straight and to the point. | ||
**Important**: This is an early version of the plugin. Please give feedback [on GitHub](https://github.com/FlorianRappl/parcel-plugin-externals/issues), especially regarding configuration and syntax. The idea is to keep the plugin simple and the options straight and to the point. | ||
@@ -67,0 +79,0 @@ ## Changelog |
15
utils.js
@@ -86,3 +86,16 @@ const { readFileSync, existsSync } = require("fs"); | ||
const plain = Object.keys(data.peerDependencies || {}); | ||
return (data.externals || []).concat(plain); | ||
const externals = data.externals || []; | ||
if (Array.isArray(externals)) { | ||
return externals.concat(plain); | ||
} else if (typeof externals === "object") { | ||
return Object.keys(externals) | ||
.map(name => `${name} => ${externals[name]}`) | ||
.concat(plain); | ||
} | ||
console.warn( | ||
`"externals" seem to be of wrong type. Expected <Array | object> but found <${typeof externals}>` | ||
); | ||
return plain; | ||
} catch (ex) { | ||
@@ -89,0 +102,0 @@ console.error(ex); |
10074
178
85