-
Notifications
You must be signed in to change notification settings - Fork 3
/
.eleventy.js
60 lines (51 loc) · 1.84 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
/* eslint-disable @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require */
const path = require('node:path')
require('@babel/register')({
extensions: ['.tsx', '.mjs', '.ts'],
only: [
/\/src\/react\//,
/\/node_modules\/react-merge-refs\//,
],
presets: [
[
'@babel/preset-env',
],
],
})
require('ts-node').register({
project: 'tsconfig.json',
transpileOnly: true,
})
const { createElement, StrictMode } = require('react')
// See https://github.com/jsx-eslint/eslint-plugin-react/issues/3606
const { renderToString } = require('react-dom/server')
const { Root } = require('./src/react/internal/test-utils/Root')
const { createNunjucksEnvironment } = require('./src/lib')
module.exports = (config) => {
config.setLibrary('njk', createNunjucksEnvironment())
config.addPassthroughCopy({ dist: '.' })
config.addWatchTarget(path.join(__dirname, 'src/react'))
config.addShortcode('react', ({ componentPath, exampleName, component }) => {
/* The eslint rule import/no-dynamic-require is asking for
* await import() however this has been difficult to get this working with ts-node
* https://github.com/TypeStrong/ts-node/issues/1548
*/
const moduleId = require.resolve(path.join(__dirname, 'src/react', componentPath))
/* Delete the module cache for @moduk/frontend/react
* when reloading to avoid SSR mismatch when making changes.
*/
delete require.cache[moduleId]
delete require.cache[require.resolve('@moduk/frontend/react')]
const { Example } = require(path.join(__dirname, 'src/react', componentPath))
return renderToString(
createElement(StrictMode, null, createElement(Root, { exampleName, component }, createElement(Example))),
)
})
return {
dir: {
data: 'data',
input: 'examples-site',
output: 'examples-site/dist',
},
}
}