@rollup/plugin-babel 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -1
- package/README.md +9 -10
- package/dist/index.es.js +3 -2
- package/dist/index.js +2 -1
- package/package.json +14 -4
- package/types/index.d.ts +106 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
+
# @rollup/plugin-babel ChangeLog
|
|
2
|
+
|
|
3
|
+
## v5.1.0
|
|
4
|
+
|
|
5
|
+
_2020-07-12_
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- feat: add typings (#462)
|
|
10
|
+
|
|
11
|
+
### Updates
|
|
12
|
+
|
|
13
|
+
- docs: add note about excluding @babel/runtime helpers via regex (#483)
|
|
14
|
+
|
|
15
|
+
## v5.0.4
|
|
16
|
+
|
|
17
|
+
_2020-06-22_
|
|
18
|
+
|
|
19
|
+
### Updates
|
|
20
|
+
|
|
21
|
+
- docs: remove unused import in "Usage" example (#460)
|
|
22
|
+
- docs: update node requirement in readme (#443)
|
|
23
|
+
- docs: fix typo in readme (#447)
|
|
24
|
+
|
|
25
|
+
## v5.0.3
|
|
26
|
+
|
|
27
|
+
_2020-06-05_
|
|
28
|
+
|
|
29
|
+
### Updates
|
|
30
|
+
|
|
31
|
+
- docs: update `babelHelpers` description (#397)
|
|
32
|
+
|
|
33
|
+
## v5.0.2
|
|
34
|
+
|
|
35
|
+
_2020-05-20_
|
|
36
|
+
|
|
37
|
+
### Bugfixes
|
|
38
|
+
|
|
39
|
+
- fix: use loadPartialConfigAsync when it is available (#359)
|
|
40
|
+
|
|
41
|
+
### Updates
|
|
42
|
+
|
|
43
|
+
- docs: Cleanup misleading leftovers in the README (#377)
|
|
44
|
+
- docs: correct breaking change note in v5 CHANGELOG (#368)
|
|
45
|
+
|
|
46
|
+
## v5.0.1
|
|
47
|
+
|
|
48
|
+
_2020-05-20_
|
|
49
|
+
|
|
50
|
+
### Bugfixes
|
|
51
|
+
|
|
52
|
+
- fix: use loadPartialConfigAsync when it is available (#359)
|
|
53
|
+
|
|
54
|
+
### Updates
|
|
55
|
+
|
|
56
|
+
- docs: Cleanup misleading leftovers in the README (#377)
|
|
57
|
+
- docs: correct breaking change note in v5 CHANGELOG (#368)
|
|
58
|
+
|
|
1
59
|
# @rollup/plugin-babel changelog
|
|
2
60
|
|
|
3
61
|
## 5.0.0
|
|
@@ -19,7 +77,7 @@ _2020-04-27_
|
|
|
19
77
|
- Minimum compatible Rollup version is 1.2.0
|
|
20
78
|
- Minimum supported Node version is 10.0.0
|
|
21
79
|
- `.custom` factory is now available as separate `createBabelInputPluginFactory` export
|
|
22
|
-
- Removed `externalHelpers` & `
|
|
80
|
+
- Removed `externalHelpers` & `runtimeHelpers` options. There is now a single `babelHelpers` option which can take one of `'bundled'`, `'inline'`, `'runtime'` and `'external'` as a value. The default is `'bundled'` which matches 4.x behavior, but it is recommended to configure this option explicitly.
|
|
23
81
|
|
|
24
82
|
## 4.3.2
|
|
25
83
|
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Using Rollup with `@rollup/plugin-babel` makes the process far easier.
|
|
|
26
26
|
|
|
27
27
|
## Requirements
|
|
28
28
|
|
|
29
|
-
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (
|
|
29
|
+
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v10.0.0+) and Rollup v1.20.0+.
|
|
30
30
|
|
|
31
31
|
## Install
|
|
32
32
|
|
|
@@ -40,7 +40,6 @@ Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/
|
|
|
40
40
|
|
|
41
41
|
```js
|
|
42
42
|
import babel from '@rollup/plugin-babel';
|
|
43
|
-
import pkg from './package.json';
|
|
44
43
|
|
|
45
44
|
const config = {
|
|
46
45
|
input: 'src/index.js',
|
|
@@ -60,7 +59,7 @@ Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#comma
|
|
|
60
59
|
|
|
61
60
|
This plugin respects Babel [configuration files](https://babeljs.io/docs/en/configuration) by default and they are generally the best place to put your configuration.
|
|
62
61
|
|
|
63
|
-
You can also run Babel on the generated chunks instead of the input files. Even though this is slower, it is the only way to transpile Rollup's auto-generated wrapper code to lower compatibility targets than ES5
|
|
62
|
+
You can also run Babel on the generated chunks instead of the input files. Even though this is slower, it is the only way to transpile Rollup's auto-generated wrapper code to lower compatibility targets than ES5, see [Running Babel on the generated code](#running-babel-on-the-generated-code) for details.
|
|
64
63
|
|
|
65
64
|
All options are as per the [Babel documentation](https://babeljs.io/docs/en/options), plus the following:
|
|
66
65
|
|
|
@@ -81,7 +80,7 @@ A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns
|
|
|
81
80
|
Type: `Array[...String]`<br>
|
|
82
81
|
Default: `['.js', '.jsx', '.es6', '.es', '.mjs']`
|
|
83
82
|
|
|
84
|
-
An array of file extensions that Babel should transpile. If you want to
|
|
83
|
+
An array of file extensions that Babel should transpile. If you want to transpile TypeScript files with this plugin it's essential to include `.ts` and `.tsx` in this option.
|
|
85
84
|
|
|
86
85
|
### `babelHelpers`
|
|
87
86
|
|
|
@@ -90,12 +89,12 @@ Default: `'bundled'`
|
|
|
90
89
|
|
|
91
90
|
It is recommended to configure this option explicitly (even if with its default value) so an informed decision is taken on how those babel helpers are inserted into the code.
|
|
92
91
|
|
|
93
|
-
We recommend to follow
|
|
92
|
+
We recommend to follow these guidelines to determine the most appropriate value for your project:
|
|
94
93
|
|
|
95
|
-
- `'runtime'` - you should use
|
|
96
|
-
- `'bundled'` - you should use
|
|
97
|
-
- `'external'` - use
|
|
98
|
-
- `'inline'` - this is not recommended. Helpers will be inserted in each file using
|
|
94
|
+
- `'runtime'` - you should use this especially when building libraries with Rollup. It has to be used in combination with `@babel/plugin-transform-runtime` and you should also specify `@babel/runtime` as dependency of your package. Don't forget to tell Rollup to treat the helpers imported from within the `@babel/runtime` module as external dependencies when bundling for `cjs` & `es` formats. This can be accomplished via regex (`external: [/@babel\/runtime/]`) or a function (`external: id => id.includes('@babel/runtime')`). It's important to not only specify `external: ['@babel/runtime']` since the helpers are imported from nested paths (e.g `@babel/runtime/helpers/get`) and [Rollup will only exclude modules that match strings exactly](https://rollupjs.org/guide/en/#peer-dependencies).
|
|
95
|
+
- `'bundled'` - you should use this if you want your resulting bundle to contain those helpers (at most one copy of each). Useful especially if you bundle an application code.
|
|
96
|
+
- `'external'` - use this only if you know what you are doing. It will reference helpers on **global** `babelHelpers` object. Used in combination with `@babel/plugin-external-helpers`.
|
|
97
|
+
- `'inline'` - this is not recommended. Helpers will be inserted in each file using this option. This can cause serious code duplication. This is the default Babel behavior as Babel operates on isolated files - however, as Rollup is a bundler and is project-aware (and therefore likely operating across multiple input files), the default of this plugin is `"bundled"`.
|
|
99
98
|
|
|
100
99
|
### `skipPreflightCheck`
|
|
101
100
|
|
|
@@ -106,7 +105,7 @@ Before transpiling your input files this plugin also transpile a short piece of
|
|
|
106
105
|
|
|
107
106
|
### External dependencies
|
|
108
107
|
|
|
109
|
-
Ideally, you should only be transforming your source code, rather than running all of your external dependencies through Babel
|
|
108
|
+
Ideally, you should only be transforming your source code, rather than running all of your external dependencies through Babel (to ignore external dependencies from being handled by this plugin you might use `exclude: 'node_modules/**'` option). If you have a dependency that exposes untranspiled ES6 source code that doesn't run in your target environment, then you may need to break this rule, but it often causes problems with unusual `.babelrc` files or mismatched versions of Babel.
|
|
110
109
|
|
|
111
110
|
We encourage library authors not to distribute code that uses untranspiled ES6 features (other than modules) for this reason. Consumers of your library should _not_ have to transpile your ES6 code, any more than they should have to transpile your CoffeeScript, ClojureScript or TypeScript.
|
|
112
111
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as babel from '@babel/core';
|
|
2
|
-
import { transformAsync, loadPartialConfig, buildExternalHelpers, DEFAULT_EXTENSIONS } from '@babel/core';
|
|
2
|
+
import { transformAsync, loadPartialConfigAsync, loadPartialConfig, buildExternalHelpers, DEFAULT_EXTENSIONS } from '@babel/core';
|
|
3
3
|
import { createFilter } from '@rollup/pluginutils';
|
|
4
4
|
import { addNamed } from '@babel/helper-module-imports';
|
|
5
5
|
|
|
@@ -192,7 +192,8 @@ async function preflightCheck(ctx, babelHelpers, transformOptions) {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
async function transformCode(inputCode, babelOptions, overrides, customOptions, ctx, finalizeOptions) {
|
|
195
|
-
|
|
195
|
+
// loadPartialConfigAsync has become available in @babel/core@7.8.0
|
|
196
|
+
const config = await (loadPartialConfigAsync || loadPartialConfig)(babelOptions); // file is ignored by babel
|
|
196
197
|
|
|
197
198
|
if (!config) {
|
|
198
199
|
return null;
|
package/dist/index.js
CHANGED
|
@@ -195,7 +195,8 @@ async function preflightCheck(ctx, babelHelpers, transformOptions) {
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
async function transformCode(inputCode, babelOptions, overrides, customOptions, ctx, finalizeOptions) {
|
|
198
|
-
|
|
198
|
+
// loadPartialConfigAsync has become available in @babel/core@7.8.0
|
|
199
|
+
const config = await (babel.loadPartialConfigAsync || babel.loadPartialConfig)(babelOptions); // file is ignored by babel
|
|
199
200
|
|
|
200
201
|
if (!config) {
|
|
201
202
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rollup/plugin-babel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -25,12 +25,14 @@
|
|
|
25
25
|
"lint:js": "eslint --fix --cache src test",
|
|
26
26
|
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
|
|
27
27
|
"prebuild": "del-cli dist",
|
|
28
|
-
"prepublishOnly": "pnpm run lint && pnpm run test && pnpm run build",
|
|
28
|
+
"prepublishOnly": "pnpm run lint && pnpm run test && pnpm run build && pnpm run test:ts",
|
|
29
29
|
"pretest": "pnpm run build",
|
|
30
|
-
"test": "ava"
|
|
30
|
+
"test": "ava",
|
|
31
|
+
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
|
|
31
32
|
},
|
|
32
33
|
"files": [
|
|
33
34
|
"dist",
|
|
35
|
+
"types",
|
|
34
36
|
"README.md",
|
|
35
37
|
"LICENSE"
|
|
36
38
|
],
|
|
@@ -44,6 +46,7 @@
|
|
|
44
46
|
],
|
|
45
47
|
"peerDependencies": {
|
|
46
48
|
"@babel/core": "^7.0.0",
|
|
49
|
+
"@types/babel__core": "^7.1.9",
|
|
47
50
|
"rollup": "^1.20.0||^2.0.0"
|
|
48
51
|
},
|
|
49
52
|
"dependencies": {
|
|
@@ -58,6 +61,7 @@
|
|
|
58
61
|
"@babel/plugin-transform-runtime": "^7.7.4",
|
|
59
62
|
"@babel/preset-env": "^7.9.0",
|
|
60
63
|
"@rollup/plugin-json": "^4.0.0",
|
|
64
|
+
"@types/babel__core": "^7.1.9",
|
|
61
65
|
"rollup": "^2.0.0",
|
|
62
66
|
"source-map": "^0.6.1"
|
|
63
67
|
},
|
|
@@ -73,5 +77,11 @@
|
|
|
73
77
|
"Bogdan Chadkin <trysound@yandex.ru>",
|
|
74
78
|
"Mateusz Burzyński <mateuszburzynski@gmail.com> (https://github.com/Andarist)"
|
|
75
79
|
],
|
|
76
|
-
"module": "dist/index.es.js"
|
|
80
|
+
"module": "dist/index.es.js",
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"@types/babel__core": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"types": "types/index.d.ts"
|
|
77
87
|
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Plugin } from 'rollup';
|
|
2
|
+
import { FilterPattern } from '@rollup/pluginutils';
|
|
3
|
+
import * as babelCore from '@babel/core';
|
|
4
|
+
|
|
5
|
+
export interface RollupBabelInputPluginOptions
|
|
6
|
+
extends Omit<babelCore.TransformOptions, 'include' | 'exclude'> {
|
|
7
|
+
/**
|
|
8
|
+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. When relying on Babel configuration files you cannot include files already excluded there.
|
|
9
|
+
* @default undefined;
|
|
10
|
+
*/
|
|
11
|
+
include?: FilterPattern;
|
|
12
|
+
/**
|
|
13
|
+
* A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. When relaying on Babel configuration files you can only exclude additional files with this option, you cannot override what you have configured for Babel itself.
|
|
14
|
+
* @default undefined;
|
|
15
|
+
*/
|
|
16
|
+
exclude?: FilterPattern;
|
|
17
|
+
/**
|
|
18
|
+
* An array of file extensions that Babel should transpile. If you want to transpile TypeScript files with this plugin it's essential to include .ts and .tsx in this option.
|
|
19
|
+
* @default ['.js', '.jsx', '.es6', '.es', '.mjs']
|
|
20
|
+
*/
|
|
21
|
+
extensions?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* It is recommended to configure this option explicitly (even if with its default value) so an informed decision is taken on how those babel helpers are inserted into the code.
|
|
24
|
+
* @default 'bundled'
|
|
25
|
+
*/
|
|
26
|
+
babelHelpers?: 'bundled' | 'runtime' | 'inline' | 'external';
|
|
27
|
+
/**
|
|
28
|
+
* Before transpiling your input files this plugin also transpile a short piece of code for each input file. This is used to validate some misconfiguration errors, but for sufficiently big projects it can slow your build times so if you are confident about your configuration then you might disable those checks with this option.
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
skipPreflightCheck?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface RollupBabelOutputPluginOptions
|
|
35
|
+
extends Omit<babelCore.TransformOptions, 'include' | 'exclude'> {
|
|
36
|
+
/**
|
|
37
|
+
* Use with other formats than UMD/IIFE.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
allowAllFormats?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type RollupBabelCustomInputPluginOptions = (
|
|
44
|
+
options: RollupBabelInputPluginOptions & Record<string, any>
|
|
45
|
+
) => {
|
|
46
|
+
customOptions: Record<string, any>;
|
|
47
|
+
pluginOptions: RollupBabelInputPluginOptions;
|
|
48
|
+
};
|
|
49
|
+
export type RollupBabelCustomOutputPluginOptions = (
|
|
50
|
+
options: RollupBabelOutputPluginOptions & Record<string, any>
|
|
51
|
+
) => {
|
|
52
|
+
customOptions: Record<string, any>;
|
|
53
|
+
pluginOptions: RollupBabelOutputPluginOptions;
|
|
54
|
+
};
|
|
55
|
+
export type RollupBabelCustomPluginConfig = (
|
|
56
|
+
cfg: babelCore.PartialConfig,
|
|
57
|
+
options: { code: string; customOptions: Record<string, any> }
|
|
58
|
+
) => babelCore.TransformOptions;
|
|
59
|
+
export type RollupBabelCustomPluginResult = (
|
|
60
|
+
result: babelCore.BabelFileResult,
|
|
61
|
+
options: {
|
|
62
|
+
code: string;
|
|
63
|
+
customOptions: Record<string, any>;
|
|
64
|
+
config: babelCore.PartialConfig;
|
|
65
|
+
transformOptions: babelCore.TransformOptions;
|
|
66
|
+
}
|
|
67
|
+
) => babelCore.BabelFileResult;
|
|
68
|
+
export interface RollupBabelCustomInputPlugin {
|
|
69
|
+
options?: RollupBabelCustomInputPluginOptions;
|
|
70
|
+
config?: RollupBabelCustomPluginConfig;
|
|
71
|
+
result?: RollupBabelCustomPluginResult;
|
|
72
|
+
}
|
|
73
|
+
export interface RollupBabelCustomOutputPlugin {
|
|
74
|
+
options?: RollupBabelCustomOutputPluginOptions;
|
|
75
|
+
config?: RollupBabelCustomPluginConfig;
|
|
76
|
+
result?: RollupBabelCustomPluginResult;
|
|
77
|
+
}
|
|
78
|
+
export type RollupBabelCustomInputPluginBuilder = (
|
|
79
|
+
babel: typeof babelCore
|
|
80
|
+
) => RollupBabelCustomInputPlugin;
|
|
81
|
+
export type RollupBabelCustomOutputPluginBuilder = (
|
|
82
|
+
babel: typeof babelCore
|
|
83
|
+
) => RollupBabelCustomOutputPlugin;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A Rollup plugin for seamless integration between Rollup and Babel.
|
|
87
|
+
* @param options - Plugin options.
|
|
88
|
+
* @returns Plugin instance.
|
|
89
|
+
*/
|
|
90
|
+
export function getBabelInputPlugin(options?: RollupBabelInputPluginOptions): Plugin;
|
|
91
|
+
export function getBabelOutputPlugin(options?: RollupBabelOutputPluginOptions): Plugin;
|
|
92
|
+
|
|
93
|
+
export function createBabelInputPluginFactory(
|
|
94
|
+
customCallback?: RollupBabelCustomInputPluginBuilder
|
|
95
|
+
): typeof getBabelInputPlugin;
|
|
96
|
+
export function createBabelOutputPluginFactory(
|
|
97
|
+
customCallback?: RollupBabelCustomOutputPluginBuilder
|
|
98
|
+
): typeof getBabelOutputPlugin;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A Rollup plugin for seamless integration between Rollup and Babel.
|
|
102
|
+
* @param options - Plugin options.
|
|
103
|
+
* @returns Plugin instance.
|
|
104
|
+
*/
|
|
105
|
+
export function babel(options?: RollupBabelInputPluginOptions): Plugin;
|
|
106
|
+
export default babel;
|