developit / developit/microbundle

Officially support more elaborate externals

オープン
#477 コメント 11 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement :rocket: Feature Request
主要言語
JavaScript
スター
8.1k
フォーク
358
PR マージ指標
30日以内にマージされた PR はありません

説明

_This is a feature request/Proposal_

As a user of microbundle I want ways to configure which imports are to be considered external.
In order to reduce my bundle size and also to work with non-standard imports (images, fonts, ...) that are not supported by microbundle.

## Status Quo

1. As described in https://github.com/developit/microbundle/issues/283#issuecomment-523879163, there is a (I guess unoffical) way to use regex in the `--exclude` flag, which can be used to have rollup treat specific import statements as external.
2. Presence of the `--exclude` flag triggers if pkg.dependencies are treated as external or not (see [index.js#L387](https://github.com/developit/microbundle/blob/master/src/index.js#L387-L388)) I find that quite confusing and the behaviour is not documented.

## Problem

Given I want to use `--external .*/assets/.*` to work with non-standard imports
And I also want all my dependencies to be excluded
Then I need to add all dependencies to `--external` causing code duplication and manual overhead.

## Proposal

In order to fix the problem and reduce confusion I propose to have it work like this:

### `$ microbundle`

Exclude `dependencies`, `peerDependencies`

### `$ microbundle --external .*/assets/.*`

Exclude `dependencies`, `peerDependencies` and `.*/assets/.*`
And explicitly support regular expressions or globs under `--external`

### `$ microbundle --external .*/assets/.*,angular --include-dependencies`

Exclude `peerDependencies` and `.*/assets/.*`
All normal dependencies ecxept `angular` are included in the bundle

## Non-breaking alternative

I realize that the above proposal is really tied to my personal usecase of (miss-?)using `--external` for non-standard imports.
It would also introduce a potential pretty impactful breaking change (since users of microbundle might ship bundles that lack bundled dependencies).

Alternatively the current behaviour could stay as is, using regex in `--external` will be considered hacky. And we introduce a new, documented way to exclude assets:

### `$ microbundle --external-glob **/*.(jpg|png)`

Exclude `dependencies`, `peerDependencies` and all imports matching `**/*.(jpg|png)`

### `$ microbundle --external angular --external-glob **/*.(jpg|png)`

Exclude `peerDependencies`, `angular`, and all imports matching `**/*.(jpg|png)`

---

Let me know what you think about this. I would be really happy to implement the changes and provide a PR.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。