The module systems of JavaScript are an incomprehensible mess, so are their resolution rules. I do like and want strong typing, but would rather not touch tsconfig for aforementioned reasons, so it’s impossible for me to maintain a typed implementation. Feel free to take the code, I’m happy to transfer the package name to appropriate prospective maintainers.
An Eleventy plugin adding multi-site support. Written in TypeScript, compiled to CommonJS.
Note
|
For simplicity, this plugin is called multisite below. |
Assume such directory layout:
sites/ blog/ index.html posts/ hello-world.adoc lorem-ipsum.adoc about.pug lab/ index.html lab.js photos/ index.pug photo1.jpg photo2.png photo3.webp
and you want them as three different sites, namingly blog, lab and photos.
You can go as-is, building them on all occurences, publishing corresponding directory for each site, AND handwriting every link.
Or you can use multisite, which build only one (or some, or all) of them for you.
$ cd sites $ pnpm add --dev eleventy-multisite # or $ npm install --save-dev eleventy-multisite
const multisite = require('eleventy-multisite')
module.exports = function(eleventyConfig) {
// your existing configurations
eleventyConfig.addPlugin(multisite, {
baseDir: 'sites/',
outDir: '_out/',
sites: '*',
})
}
{
"scripts": {
"m11ty": "pnpm exec eleventy-multisite",
"m11ty": "npm exec eleventy-multisite"
}
}
# with the script alias above $ pnpm m11ty # build all sites (directories) under `config.baseDir` # or $ npm run m11ty $ pnpm m11ty onedown --watch # watch and build `onedown` under `config.baseDir` $ pnpm m11ty blog --serve # watch and serve `${config.baseDir}/blog`
$ pnpm run eleventy-multisite $ pnpm run eleventy-multisite site1 glob* # or $ npm run eleventy-multisite $ npm run eleventy-multisite site1 glob*
-
-b
,--basedir
base directory of sites, overridesconfig.baseDir
, defaultsites/
; respects.gitignore
and ignores--outdir
-
-o
,--outdir
base directory of output, overridesconfig.outDir
, default_out/
-
-c
,--config
configuration file path, default.eleventy.js
-
-E
,--exclude
exclude this glob pattern, can be specified multiple times -
-w
,--watch
watch and rebuild as source files change -
-S
,--serve
start a web server serving built site, automatically--watch
-
-p
,--port
serve at this port, default8080
(Eleventy default) -
-n
,--dryrun
don’t write to disk; passed to Eleventy -
-P
,--pathprefix
see Eleventy doc; passed to Eleventy
Note
|
Due to the multi-action nature of multisite,
you can’t The |
Positional arguments (ones not starting with --
or -
) are interpreted as site name patterns,
searched for under --basedir
or config.baseDir
.
See the fast-glob
package for pattern syntax.
If no positional argument is given, patterns defined in configuration option
sites
(see below) will be used.
Sites may have their own .eleventy.js
configuration file, and also have their config file path
defined in config.sites[].configPath
.
Configurations are applied in following order:
-
Global configuration
-
Site-specific configuration
-
Command line arguments
This plugin is configured through the top-level configuration file usually named .eleventy.js
.
It reads the same --config
option as Eleventy does, so you can use a different file name.
// .eleventy.js
module.exports = function(eleventyConfig) {
// your existing configuration
// exactly match three sites, with default config
let options = {
sites: ['blog', 'lab', 'photos'],
}
// match all sites starting with `site-`, and `blog` with site-specific config;
// write all output to `_build/` instead of `_out/`
options = {
outDir: '_build/',
sites: [
'site-*',
['blog', {
outDir: '_blog',
configPath: '.blog.eleventy.js',
}],
],
}
// use the default config: all visible directories under `sites/`, write to `_out/`
options = {}
eleventyConfig.addPlugin(require('eleventy-multisite'), options)
}
Base search directory. Default is sites/
.
config.outDir
will be excluded to prevent previous output being "rebuilt".
If .gitignore
is present, its rules are respected.
Base output directory.
Each site, unless individually specified, will be built in ${outDir}/${site}
.
Default is _out/
.
May be an array of or a single site spec.
Each site spec may be a
-
glob pattern, or
-
tuple of glob pattern and site-specific config
Each pattern is appended a /
, to filter out only the directories.
Default is ['*']
, meaning all visible directories under config.baseDir
.
See Eleventy doc.
See Eleventy doc.