You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add require.context for Vue automatic global component registration #723
What I'm trying to do:
I would like to use the automatic global component registration from Vue as outlined in this guide.
This approach however relies on webpacks require.context method, which is outlined here.
Problem require.context does not seem to be support by codesandbox (❤) yet, which is why it throws the following error:
My request
Could you please add support for require.context, since this would enable global auto registration which allows us to omit tedious component imports everywhere and make it even easier for beginners to get started with Vue (imo).
Very good request, makes a lot of sense to add this. I'm actually surprised that we didn't see this request before 😄.
If I understand the behaviour of require.context well enough it should work like this:
constreq=require.context('./components',true,/.*\.vue$/)// Now we have a 'context' that behaves the same as require but with context, sooreq.resolve('App.vue')// Will resolve components/App.vuereq.keys()// Will return all keys indexed by the contextreq('App.vue')// Will `require` components/App.vue and return the module
I can't give a timeline on when this will be done, but it's high on my priority list!
Reacted by JollyBrackets, Jukka Raimovaara, Yawen Xiao, Victor Muštar, Raymond Tijhaar, Sumurai8, Ragaar, Alexei Strasser and Leon White
importVuefrom"vue";constrequireComponent=require.context("../components",false,/\.vue$/);requireComponent.keys().forEach(filename=>{constcomponent=requireComponent(filename)/* Get componenent name from filename IE. "/components/component-name.vue" to "ComponentName" */constcomponentName=filename.split("/").pop().replace(/\.\w+$/,"").replace(/-([a-z])/g,g=>g[1].toUpperCase()).replace(/(\b\w)/gi,m=>m.toUpperCase());Vue.component(componentName,component.default||component);/* Global component registration */});
Any news if and when we could get require.context working on client templates?
Is there a workaround until this is implemented? Would love to be able to show off some work I have done, but can't figure out how to work around this error...
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
Any change getting this feature implemented? This would really help people who is just starting to code. Also this feature would lower mental overhead, because all components would be automatically available when needed.
we practically can not do any real work on codesandbox if this is not supported!
We are building a prototype of an SPA using Vue and Vuetify and we are to the point that we need to use require.context in several places but we obviously can't!
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.
Activity
CompuIves commentedon Apr 12, 2018
Very good request, makes a lot of sense to add this. I'm actually surprised that we didn't see this request before 😄.
If I understand the behaviour of
require.contextwell enough it should work like this:I can't give a timeline on when this will be done, but it's high on my priority list!
Napzu commentedon Jul 7, 2019
I made simple as possible example that works fine in container sandbox but obviously not in client template.
Any news if and when we could get require.context working on client templates?
hendrul commentedon Jan 8, 2020
How is it doing? what's been done? anything on this issue? it is a very important feature, I depend on this to import lots of images, and other files.
strophy commentedon Feb 3, 2020
Is there a workaround until this is implemented? Would love to be able to show off some work I have done, but can't figure out how to work around this error...
github-actions commentedon Sep 4, 2020
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.
Napzu commentedon Sep 4, 2020
Any change getting this feature implemented? This would really help people who is just starting to code. Also this feature would lower mental overhead, because all components would be automatically available when needed.
unitedworx commentedon Sep 17, 2020
we practically can not do any real work on codesandbox if this is not supported!
We are building a prototype of an SPA using Vue and Vuetify and we are to the point that we need to use require.context in several places but we obviously can't!
any updates on this? or workarounds at least???
github-actions commentedon Dec 20, 2020
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.
jonaskuske commentedon Dec 20, 2020
...just letting the bot know it's not resolved yet
(if it works like that and doesn't need a maintainer to comment)
github-actions commentedon Mar 25, 2021
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.
jonaskuske commentedon Apr 3, 2021
.
rowild commentedon May 12, 2021
Jumping in... have the same problem with vuex store and modules setup.
hendrul commentedon May 13, 2021
No need for this, it is way better and compatible to use import-all.macro instead
github-actions commentedon Aug 12, 2021
This issue has automatically been marked stale because there has been no activity in a while. Please leave a comment if the issue has not been resolved, or if it is not stale for any other reason. After 2 weeks, this issue will automatically be closed, unless a comment is made or the stale label is removed.