-
-
Notifications
You must be signed in to change notification settings - Fork 500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes in dependencies to your Eleventy config file don’t cause the config file to be reloaded #1052
Comments
Also seeing this issue and spent waaayyyy too long trying to figure it out. |
This is labelled as an enhancement, but I think it might be better considered a bug? |
I was thinking that after creating the ticket too but not sure how to change it |
@zachleat could you help us get this labelled as a bug? (or give some guidance on whether it is a bug or expected behavior) |
I cannot speak for @zachleat, but I've come to see this as "expected" behavior. It's akin to modifying the |
@reubenlillie Hmm... I guess it seems different to me than modifying the |
@chasemccoy, right. Even though shortcodes, filters, and so forth can reside in separate modules that you pass |
That makes a lot of sense. Thanks @reubenlillie! |
Actually, there is a config reset in watch mode, which is (only) triggered if I first thought, an easy workaround could be using the So a built-in way could perhaps be, to provide an option like @zachleat What do you think? Are there any disadvantages in providing something like this? |
Sorry to chime in super late here, y’all. This is indeed a bug. The goal is to not require re-starting the dev server (ever). But we have some work to get there, I think. @jens-t Desired behavior would be that if a dependency of the config file changes it would reload the config, see https://www.11ty.dev/docs/watch-serve/#watch-javascript-dependencies I don’t think we need to add extra APIs here since we know the dependencies? |
@zachleat The dependencies are not known for dynamic imports. Or maybe just not in my usecase? I build an autoloader for my 11ty projects, so that all i have to do, is to create new files to add filter, shortcodes, transforms, tags and collections. This autoloader uses dynamic imports. Example code for the autoloader: const initAutoload = conf => {
const typeMapping = [
{
type: 'filter',
extension: 'js',
method: 'addFilter'
},
{
type: 'tags',
extension: 'js',
method: 'addNunjucksTag'
},
{
type: 'collections',
extension: 'js',
method: 'addCollection'
},
{
type: 'shortcodes',
extension: 'js',
method: (name, content) => {
if (!content.paired || content.paired !== true) {
(!content.async || content.async !== true)
? conf.addNunjucksShortcode(name, content.shortcode)
: conf.addNunjucksAsyncShortcode(name, content.shortcode);
}
else {
(!content.async || content.async !== true)
? conf.addPairedNunjucksShortcode(name, content.shortcode)
: conf.addPairedNunjucksAsyncShortcode(name, content.shortcode);
}
}
},
{
type: 'transforms',
extension: 'js',
method: 'addTransform'
}
];
const initType = data => {
const files = path.resolve(conf11ty.paths[data.type]) + '/**/*.' + data.extension;
glob.sync(files).forEach(file => {
const name = path.parse(file).name;
const content = require(file);
typeof data.method === 'function'
? data.method(name, content)
: conf[data.method](name, content);
});
};
typeMapping.forEach(initType);
}; |
I think this is related. I import JS files from a separate directory to use in my It looks like you can work around this by using the decache package and hook into the I use the esm package but this should work with require statements as well I think. // .eleventy.js
import decache from 'decache';
export default function (config) {
config.addWatchTarget('../examples/**/*.js');
config.on('eleventy.beforeWatch', async (files) => {
files.forEach(file => decache(file));
});
...
} |
Circling back here, this might get fixed with #2147, shipped with Can anyone confirm or deny? |
I can confirm the specific issue of modifying the dependency file is still present. The first hurdle to cover here is that Update this was fixed awhile back 11ty/eleventy-base-blog@75e71ad As for the shortcode updates, stay tuned |
The fix for this will ship with 2.0.0-canary.11 |
Is anyone getting this issue in 11ty 3? I'm on alpha 5, I'm using JavaScript components in a nested import HeaderNav from './_src/components/global/HeaderNav.js';
export default function (eleventyConfig) {
eleventyConfig.addShortcode('HeaderNav', function HeaderNavShortcode(currentPageUrl) {
return new HeaderNav().render(currentPageUrl);
});
// The below makes no difference. Components changes are not reflected on refresh.
// eleventyConfig.setServerOptions({
// watch: ['_src/components/**/*.js'],
// });
} Changes to HeaderNav trigger a refresh but the actual changes are not reflected unless I kill the server and start it up again. I should probably make a new issue for this if I can replicate. |
@notacouch Please see #3270 for a possible workaround. |
Is your feature request related to a problem? Please describe.
When a shortcode is defined in an external files and being
require
into.eleventy.js
, modifying the shortcode will not reload the siteReproduce steps:
https://github.com/dephiros/11ty-tailwind/
and checkout11ty-require-reload
yarn && yarn serve
TEST
andTEST REQUIRE
.eleventy.js
and modifyTest
shortcode, notice the browser will reload with the new change_11ty/Test.js
and change some text, notice the terminal is showing reload but the browser does not reflect the changeDescribe the solution you'd like
Change in code that is
required
by.eleventy.js
should reflect in the browserDescribe alternatives you've considered
I saw the issues mentioned in #325 but it does not fix for me even with watch target. The shortcodes is still cached and require restarting the server
The text was updated successfully, but these errors were encountered: