














Is your .eleventy.js file getting too large? You can create your own plugin to move some code out.
First, create a plugin file. We recommend creating a config or _config folder in your project to store config files in. Make sure that folder isn’t getting copied out to your built site (via ignores). Then create a file in that folder. It doesn’t matter what you name it.
config/local-plugin.js
export default function(eleventyConfig) {
// Move any code from `eleventy.config.js` here.
// Use eleventyConfig as you would in your top-level config file
}
module.exports = function(eleventyConfig) {
// Move any code from `eleventy.config.js` here.
// Use eleventyConfig as you would in your top-level config file
}
Any variables defined in your eleventy.config.js file will not be available to your plugin. Consider moving those variables into your plugin file, or passing them in as options.
Next, use the addPlugin method:
eleventy.config.js
import localPlugin from "./config/local-plugin.js";
export default function(eleventyConfig) {
eleventyConfig.addPlugin(localPlugin);
}
const localPlugin = require("./config/local-plugin.js");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(localPlugin);
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。