@rollup-extras/plugin-size 0.2.1 → 0.3.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/README.md CHANGED
@@ -108,6 +108,7 @@ size({
108
108
  gzip: true,
109
109
  brotli: true,
110
110
  pluginName: "my-size",
111
+ outputPlugin: false,
111
112
  minify: async (fileName, code) => {
112
113
  // your minification logic
113
114
  return minifiedCode;
@@ -115,16 +116,34 @@ size({
115
116
  });
116
117
  ```
117
118
 
119
+ ### Output plugin usage
120
+
121
+ The plugin can also be used as an output plugin (inside `output.plugins`). Because
122
+ Rollup rejects input-only hooks like `buildStart` in that position, pass
123
+ `outputPlugin: true` to skip attaching them:
124
+
125
+ ```js
126
+ export default {
127
+ input: "src/index.js",
128
+ output: {
129
+ dir: "dist",
130
+ format: "es",
131
+ plugins: [size({ outputPlugin: true })],
132
+ },
133
+ };
134
+ ```
135
+
118
136
  ## Options
119
137
 
120
- | Option | Type | Default | Description |
121
- | ------------- | ---------- | ------------------------------ | ----------------------------------------------------------------------------------------------- |
122
- | `statsFile` | `string` | `'.stats.json'` | Path to the JSON stats file (relative to project root or absolute). |
123
- | `updateStats` | `boolean` | `true` | Whether to overwrite the stats file with the current build data. |
124
- | `gzip` | `boolean` | `true` | Report gzip-compressed sizes. |
125
- | `brotli` | `boolean` | `false` | Report brotli-compressed sizes. |
126
- | `pluginName` | `string` | `'@rollup-extras/plugin-size'` | Override the plugin name reported to Rollup. |
127
- | `minify` | `function` | `undefined` | Optional async function `(fileName, code) => minifiedCode` to minify chunks before compression. |
138
+ | Option | Type | Default | Description |
139
+ | -------------- | ---------- | ------------------------------ | ----------------------------------------------------------------------------------------------- |
140
+ | `statsFile` | `string` | `'.stats.json'` | Path to the JSON stats file (relative to project root or absolute). |
141
+ | `updateStats` | `boolean` | `true` | Whether to overwrite the stats file with the current build data. |
142
+ | `gzip` | `boolean` | `true` | Report gzip-compressed sizes. |
143
+ | `brotli` | `boolean` | `false` | Report brotli-compressed sizes. |
144
+ | `pluginName` | `string` | `'@rollup-extras/plugin-size'` | Override the plugin name reported to Rollup. |
145
+ | `outputPlugin` | `boolean` | `false` | Set to `true` when using the plugin in `output.plugins` (see [Output plugin usage](#output-plugin-usage)). |
146
+ | `minify` | `function` | `undefined` | Optional async function `(fileName, code) => minifiedCode` to minify chunks before compression. |
128
147
 
129
148
  ## How it works
130
149
 
package/index.d.ts CHANGED
@@ -20,6 +20,7 @@ declare module '@rollup-extras/plugin-size' {
20
20
  updateStats?: boolean;
21
21
  gzip?: boolean;
22
22
  brotli?: boolean;
23
+ outputPlugin?: boolean;
23
24
  minify?: (code: string, fileName: string) => Promise<string>;
24
25
  };
25
26
  export type ChunkSizeStats = {
package/index.d.ts.map CHANGED
@@ -14,6 +14,6 @@
14
14
  "sourcesContent": [
15
15
  null
16
16
  ],
17
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;",
17
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;",
18
18
  "ignoreList": []
19
19
  }
package/index.js CHANGED
@@ -193,11 +193,12 @@ export default function (options) {
193
193
  updateStats: true,
194
194
  gzip: true,
195
195
  brotli: false,
196
+ outputPlugin: false,
196
197
  },
197
198
  factories
198
199
  );
199
200
 
200
- const { pluginName, statsFile, updateStats, logger, minify: minifyFn } = normalizedOptions;
201
+ const { pluginName, statsFile, updateStats, outputPlugin, logger, minify: minifyFn } = normalizedOptions;
201
202
 
202
203
  const flags = { gzip: normalizedOptions.gzip, brotli: normalizedOptions.brotli };
203
204
 
@@ -205,11 +206,13 @@ export default function (options) {
205
206
 
206
207
  const instance = multiConfigPluginBase(false, pluginName, reportAndSave, onEachOutput);
207
208
 
208
- instance.buildStart = () => {
209
- currentStats.entries = undefined;
210
- currentStats.chunks = undefined;
211
- currentStats.assets = undefined;
212
- };
209
+ if (!outputPlugin) {
210
+ instance.buildStart = () => {
211
+ currentStats.entries = undefined;
212
+ currentStats.chunks = undefined;
213
+ currentStats.assets = undefined;
214
+ };
215
+ }
213
216
 
214
217
  return instance;
215
218
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.1",
2
+ "version": "0.3.0",
3
3
  "license": "MIT",
4
4
  "name": "@rollup-extras/plugin-size",
5
5
  "author": "Konstantin Shutkin",