-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
71 lines (68 loc) · 2.02 KB
/
.eleventy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const {writeFile, mkdir} = require('fs/promises')
const {dirname, resolve} = require('path')
const defaults = require('./src/defaults')
const {process} = require('./src/index')
module.exports = function (eleventyConfig, _options) {
// merge default and options
const options = {
...defaults,
input: eleventyConfig.dir.input,
output: eleventyConfig.dir.output,
..._options,
}
eleventyConfig.addTransform(
'eleventy-plugin-concat-transform',
async function(content) {
if(this.page.outputPath && this.page.outputPath.endsWith(".html")) {
console.log(`[11ty][Concat Plugin] Optimizing ${this.outputPath}`)
const jsOutput = resolve(
eleventyConfig.dir.output,
options.jsPath(this.page)
)
const cssOutput = resolve(
eleventyConfig.dir.output,
options.cssPath(this.page)
)
await mkdir(
dirname(jsOutput),
{ recursive: true }
)
await mkdir(
dirname(cssOutput),
{ recursive: true }
)
const [html, js, css] = await process(this.page, content, options)
await writeFile(jsOutput, js)
await writeFile(cssOutput, css)
return html
}
return content
}
)
/**
* dir: { input: '.', includes: '_includes', data: '_data', output: '_site' },
* runMode: 'serve',
* outputMode: 'fs'
*/
// eleventyConfig.on(
// "eleventy.before",
// ({ dir, runMode, outputMode }) => console.log('eleventy.before', { dir, runMode, outputMode })
// )
/**
* dir: { input: '.', includes: '_includes', data: '_data', output: '_site' },
* results: [
* {
* inputPath: './src/test.html',
* outputPath: '_site/test/index.html',
* url: '/test/',
* content: 'test\n'
* }
* ],
* runMode: 'serve',
* outputMode: 'fs'
*/
// eleventyConfig.on(
// "eleventy.after",
// ({ dir, results, runMode, outputMode }) => console.log('eleventy.after', { dir, results, runMode, outputMode })
// )
}