I'm currently working on a project in VueJs
using webpack
. As part of this, I need to dynamically include config/routing
files from specific folders. Here is an example of my folder structure:
plugins
|----Ecommerce
|--------backend
|--------frontend
|------------config.js
|------------routes.js
|------------components
|----------------products.vue
|----Blog
|--------backend
|--------frontend
|------------config.js
|------------routes.js
|------------components
|----------------posts.vue
My approach to including these files is as follows:
const configRequire = require.context('./../plugins/', true, /\.\/[^/]+\/config\.js$/);
const routesRequire = require.context('./../plugins/', true, /\.\/[^/]+\/routes\.js$/);
However, I've encountered an issue where the files are not being included, and I suspect it may be due to an error in my regex pattern.
Update:
After investigating further, I realized that my files were not being imported because they are nested within folders/subfolders
. When I restructured my folders like this:
plugins
|----Ecommerce
|--------backend
|--------config.js
|--------routes.js
|--------frontend
|------------components
|----------------products.vue
|----Blog
|--------backend
|--------config.js
|--------routes.js
|--------frontend
|------------components
|----------------posts.vue
I was able to successfully import my files. Unfortunately, I am facing issues when attempting to keep the config/routes
files inside the frontend
folder.
If anyone can provide guidance on how to resolve this issue, I would greatly appreciate it. Thank you.