Skip to content
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

Add require.context for Vue automatic global component registration #723

Closed
JollyBrackets opened this issue Apr 11, 2018 · 14 comments
Closed
Labels
🎒 Bundler Refers to CodeSandbox's In-Browser Bundler 🤔 Improvement

Comments

@JollyBrackets
Copy link

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:

image

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).

Codesandbox
https://codesandbox.io/s/github/MPH-Bali/green-village-project/tree/develop/public

Software Name/Version
Сodesandbox PROD-1523452809
Browser Chrome/65.0.3325.181
Operating System Windows/10.0.16299
@CompuIves
Copy link
Member

CompuIves commented 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.context well enough it should work like this:

const req = require.context('./components', true, /.*\.vue$/)

// Now we have a 'context' that behaves the same as require but with context, soo

req.resolve('App.vue') // Will resolve components/App.vue
req.keys() // Will return all keys indexed by the context
req('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!

@lbogdan lbogdan added the 🎒 Bundler Refers to CodeSandbox's In-Browser Bundler label Mar 22, 2019
@Napzu
Copy link

Napzu commented Jul 7, 2019

I made simple as possible example that works fine in container sandbox but obviously not in client template.

import Vue from "vue";

const requireComponent = require.context("../components", false, /\.vue$/);
requireComponent.keys().forEach(filename => {
  const component = requireComponent(filename)
  /* Get componenent name from filename IE. "/components/component-name.vue" to "ComponentName" */
  const componentName = 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?

@hendrul
Copy link

hendrul commented 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
Copy link

strophy commented 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
Copy link

github-actions bot commented 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.

@github-actions github-actions bot added the stale label Sep 4, 2020
@Napzu
Copy link

Napzu commented 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
Copy link

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
Copy link

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.

@github-actions github-actions bot added the stale label Dec 20, 2020
@jonaskuske
Copy link

jonaskuske commented 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 github-actions bot removed the stale label Dec 21, 2020
@github-actions
Copy link

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.

@github-actions github-actions bot added the stale label Mar 25, 2021
@jonaskuske
Copy link

...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 github-actions bot removed the stale label Apr 4, 2021
@rowild
Copy link
Contributor

rowild commented May 12, 2021

Jumping in... have the same problem with vuex store and modules setup.

@hendrul
Copy link

hendrul commented May 13, 2021

No need for this, it is way better and compatible to use import-all.macro instead

@github-actions
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎒 Bundler Refers to CodeSandbox's In-Browser Bundler 🤔 Improvement
Projects
None yet
Development

No branches or pull requests