Skip to content

Commit bf29262

Browse files
committed
More readme love
1 parent b8c32ac commit bf29262

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10-
[{package.json,.*rc,*.yml}]
10+
[{package.json,.*rc,*.yml,*.md}]
1111
indent_style = space
1212
indent_size = 2
1313

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,37 @@ export default {
3030
```
3131

3232

33+
## Complex Example
34+
35+
This example is more practical. Rollup places exports at the end of your bundle, which can often create single-use variables that Uglify does not collapse. Let's implement a find & replace that "moves" the export inline to save some bytes.
36+
37+
In this example, we'll make use of the fact that find/replacement pairs are executed in sequence. The first pair is used both to remove the existing export statement _and_ to find the export type & identifier. By the time the second find/replace pair is processed, it can make use of the values found in the first pass.
38+
39+
```js
40+
import postprocess from 'rollup-plugin-postprocess';
41+
42+
let name, exportPrefix;
43+
export default {
44+
plugins: [
45+
postprocess([
46+
[
47+
/(module\.exports\s*=\s*|export\s*default\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)[;,]?/,
48+
(str, prefix, id) => {
49+
name = id;
50+
exportPrefix = prefix;
51+
// returning nothing is the same as an empty string
52+
}
53+
],
54+
[
55+
/^function\s([a-zA-Z$_][a-zA-Z0-9$_]*)/,
56+
(str, id) => id==name ? `${exportPrefix} function` : str
57+
]
58+
])
59+
]
60+
};
61+
```
62+
63+
3364
## License
3465

3566
[MIT](https://oss.ninja/mit/developit)

0 commit comments

Comments
 (0)