Skip to content

Commit 91c70d7

Browse files
committed
Use ESM in the configuration examples
1 parent 28a8b6e commit 91c70d7

File tree

10 files changed

+208
-270
lines changed

10 files changed

+208
-270
lines changed

src/css.md

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ faucet-pipeline-css offers bundling for files written in CSS.
1010
To enable this **beta module** you need to add the following lines to your
1111
faucet.config.js:
1212

13-
```
14-
module.exports = {
15-
// ...
16-
plugins: [
17-
require("faucet-pipeline-css")
18-
]
19-
}
13+
```js
14+
export const plugins = [
15+
require("faucet-pipeline-css")
16+
];
2017
```
2118

2219
The configuration is an array of bundles you want to create. Each entry of the
@@ -25,15 +22,13 @@ compiled, and `target` is the file that should be created (the path is, of
2522
course, modified a little when you use fingerprinting):
2623

2724
```js
28-
module.exports = {
29-
css: [{
30-
source: "./example.css",
31-
target: "./output/example.css"
32-
}, {
33-
source: "./example2.css",
34-
target: "./output/subfolder/example2.css"
35-
}]
36-
};
25+
export const css = [{
26+
source: "./example.css",
27+
target: "./output/example.css"
28+
}, {
29+
source: "./example2.css",
30+
target: "./output/subfolder/example2.css"
31+
}];
3732
```
3833

3934
To support fingerprinting of images and fonts, use `faucet-pipeline-static` to
@@ -61,27 +56,23 @@ If you don't want to prefix your CSS even though you have a Browserslist
6156
configuration, you can deactivate it per bundle:
6257

6358
```js
64-
module.exports = {
65-
css: [{
66-
source: "./example.scss",
67-
target: "./output/example.css",
68-
browserslist: false
69-
}]
70-
};
59+
export const css = [{
60+
source: "./example.scss",
61+
target: "./output/example.css",
62+
browserslist: false
63+
}];
7164
```
7265

7366
If you use groups in your Browserslist, faucet-pipeline uses the `default` group
7467
by default. If you want to choose a different one, you can, for example, set it to
7568
"legacy" like this:
7669

7770
```js
78-
module.exports = {
79-
css: [{
80-
source: "./example.scss",
81-
target: "./output/example.css",
82-
browserslist: "legacy"
83-
}]
84-
};
71+
export const css = [{
72+
source: "./example.scss",
73+
target: "./output/example.css",
74+
browserslist: "legacy"
75+
}];
8576
```
8677

8778
## Compacting

src/faq.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ This typically happens when importing a module that has already been bundled or
1111
otherwise provides a distribution. The solution is to skip transpilation there:
1212

1313
```javascript
14-
module.exports = {
15-
js: [{
16-
source: "./index.js",
17-
target: "./dist/bundle.js",
18-
esnext: {
19-
// ...
20-
exclude: ["jquery"]
21-
}
22-
}]
23-
}
14+
export const js = [{
15+
source: "./index.js",
16+
target: "./dist/bundle.js",
17+
esnext: {
18+
// ...
19+
exclude: ["jquery"]
20+
}
21+
}];
2422
```
2523

2624
(This is necessary because faucet assumes we're consuming ES6 modules by

src/images.md

Lines changed: 50 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ folder, and `target` is the target folder.
1313
The resulting configuration might look something like this:
1414

1515
```js
16-
module.exports = {
17-
images: [{
18-
source: "./images",
19-
target: "./public/images"
20-
}]
21-
};
16+
export const images = [{
17+
source: "./images",
18+
target: "./public/images"
19+
}];
2220
```
2321

2422
This will copy the images in the supported formats by default. The files will
@@ -36,27 +34,23 @@ i.e. those for which the function returns `true` – will be copied.
3634
In this example, we only optimize `.svg` files:
3735

3836
```js
39-
module.exports = {
40-
images: [{
41-
source: "./images",
42-
target: "./public/images",
43-
filter: file => file.endsWith(".svg")
44-
}]
45-
}
37+
export const images = [{
38+
source: "./images",
39+
target: "./public/images",
40+
filter: file => file.endsWith(".svg")
41+
}];
4642
```
4743

4844
## Configuring the quality
4945

5046
You can also provide a quality as a value between 1 and 100.
5147

5248
```js
53-
module.exports = {
54-
images: [{
55-
source: "./images",
56-
target: "./public/images",
57-
quality: 60
58-
}]
59-
};
49+
export const images = [{
50+
source: "./images",
51+
target: "./public/images",
52+
quality: 60
53+
}];
6054
```
6155

6256
This will configure the quality of all lossy formats (all formats except PNG and
@@ -67,13 +61,11 @@ SVG). The quality is set to a 50 (AVIF/WebP) or 80 (PNG/JPG) by default.
6761
You can output the image in one of the supported formats.
6862

6963
```js
70-
module.exports = {
71-
images: [{
72-
source: "./images",
73-
target: "./public/images",
74-
format: "webp"
75-
}]
76-
};
64+
export const images = [{
65+
source: "./images",
66+
target: "./public/images",
67+
format: "webp"
68+
}];
7769
```
7870

7971
Note that SVGs can be converted to all other formats. But converting a vector
@@ -84,13 +76,11 @@ image format to SVG will result in an error.
8476
You can add a suffix to the output name:
8577

8678
```js
87-
module.exports = {
88-
images: [{
89-
source: "./images",
90-
target: "./public/images",
91-
suffix: "-optimized"
92-
}]
93-
};
79+
export const images = [{
80+
source: "./images",
81+
target: "./public/images",
82+
suffix: "-optimized"
83+
}];
9484
```
9585

9686
This will output a file named `foo.png` as `foo-optimized.png`. This is
@@ -103,14 +93,12 @@ To scale the images, you can provide a scaling factor. To create a version half
10393
the size, with the suffix `-small` you can use the following configuration:
10494

10595
```js
106-
module.exports = {
107-
images: [{
108-
source: "./images",
109-
target: "./public/images",
110-
scale: 0.5,
111-
suffix: "-small"
112-
}]
113-
};
96+
export const images = [{
97+
source: "./images",
98+
target: "./public/images",
99+
scale: 0.5,
100+
suffix: "-small"
101+
}];
114102
```
115103

116104
You can also provide a target width and/or height. By default, the pipeline
@@ -120,32 +108,28 @@ create files with the suffix `-thumbnail` with a maximum width of 300 and a
120108
maximum height of 300, keeping the ratio.
121109

122110
```js
123-
module.exports = {
124-
images: [{
125-
source: "./images",
126-
target: "./public/images",
127-
width: 300,
128-
height: 300,
129-
suffix: "-thumbnail"
130-
}]
131-
};
111+
export const images = [{
112+
source: "./images",
113+
target: "./public/images",
114+
width: 300,
115+
height: 300,
116+
suffix: "-thumbnail"
117+
}];
132118
```
133119

134120
You can also resize without keeping the ratio -- the resulting image will have
135121
the exact dimension you specify. The image will be cropped vertically or
136122
horizontally so that no empty space remains.
137123

138124
```js
139-
module.exports = {
140-
images: [{
141-
source: "./images",
142-
target: "./public/images",
143-
width: 300,
144-
height: 300,
145-
crop: true,
146-
suffix: "-square"
147-
}]
148-
};
125+
export const images = [{
126+
source: "./images",
127+
target: "./public/images",
128+
width: 300,
129+
height: 300,
130+
crop: true,
131+
suffix: "-square"
132+
}];
149133
```
150134

151135
## Autorotate
@@ -154,11 +138,9 @@ You can configure the pipeline to rotate images automatically according to their
154138
EXIF data:
155139

156140
```js
157-
module.exports = {
158-
images: [{
159-
source: "./images",
160-
target: "./public/images",
161-
autorotate: true
162-
}]
163-
};
141+
export const images = [{
142+
source: "./images",
143+
target: "./public/images",
144+
autorotate: true
145+
}];
164146
```

src/index.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,29 @@ details.
1414
Creating a CSS bundle from [Sass](http://sass-lang.com) modules:
1515

1616
```javascript
17+
export const sass = [{
1718
source: "./styles/index.scss",
1819
target: "./dist/bundle.css"
20+
}];
1921
```
2022

2123
Bundling and transpiling JavaScript:
2224

2325
```javascript
26+
export const js = [{
2427
source: "./src/index.js",
2528
target: "./dist/bundle.js",
2629
esnext: true // activates ES6 transpiler
30+
}];
2731
```
2832

2933
Fingerprinting arbitrary files, like fonts and images:
3034

3135
```javascript
36+
export const static = [{
3237
source: "./assets",
3338
target: "./dist/assets"
39+
}];
3440
```
3541

3642

@@ -48,12 +54,10 @@ Configuration resides in `faucet.config.js` – in this case, we want to bundle
4854
our JavaScript::
4955

5056
```javascript
51-
module.exports = {
52-
js: [{
53-
source: "./src/index.js",
54-
target: "./dist/bundle.js"
55-
}]
56-
};
57+
export const js = [{
58+
source: "./src/index.js",
59+
target: "./dist/bundle.js"
60+
}];
5761
```
5862

5963
Let's create two source files within the `src` directory, `index.js` and

0 commit comments

Comments
 (0)