vue-components-autodetect-webpack子目录未加斜杠致项目无法运行
Hey there, let's get that subdirectory slash issue sorted out so your project can run smoothly! The problem you're hitting is likely because the loader isn't correctly handling path separators for components in subdirectories of your pages folder, leading to invalid file paths Webpack can't resolve.
Here's what you can do to fix it:
Add a trailing slash to your
pathoption
The most common culprit here is missing a trailing slash at the end of your target directory path. Without it, the loader might concatenate subdirectory names and component filenames without the necessary slash separator, breaking path resolution.Update your Webpack loader config's
pathvalue to include a trailing slash:{ test: /\.ts$/, exclude: /node_modules/, use: [ { loader: 'vue-components-autodetect-webpack', options: { path: path.resolve(__dirname, './frontend/pages/'), // Added trailing slash here separator: '-', injectComment: /(\/\/\s*{{\s*inject-vue-components\s*}}\n?)/ig, exclude: ... // Keep your existing exclude rules } } ] }Double-check your
excluderules
Make sure yourexcludeconfiguration isn't accidentally filtering out subdirectories insidepages. If any of your exclude patterns match paths in those subdirectories, the loader won't process those components, which could also lead to runtime errors.
Why this works:
When the path ends with a slash, the loader correctly appends subdirectory names and component filenames with proper path separators. Without it, it might generate paths like frontend/pagesSubdirectoryComponent.vue instead of frontend/pages/subdirectory/Component.vue—which Webpack can't find, causing your project to fail to run.
内容的提问来源于stack exchange,提问作者olvenmage

