'Nuxt plugin does not copy imported files to .nuxt
In a Nuxt project (version 2.14.9) I have a plugin file /plugins/ui-components.js that starts like this:
import UiList from '../components/UiList.vue'
import UiPageHeading from '../components/UiPageHeading.vue'
// more imports etc.
In nuxt.config.js I reference a file like this:
{
// ...
buildModules: [
{
handler: require('../lib/module.js'),
options: {},
},
],
}
Finally in ..lib/module.js I have
this.addPlugin({
fileName: path.join(OUTPUT_DIR, 'plugins', 'ui-components.js'),
src: path.resolve(__dirname, 'plugins/ui-components.js'),
options: {
registerDynamicComponentGlobally:
options.registerDynamicComponentGlobally,
},
})
Now when I build or run the project ui-components.js gets copied to .nuxt, but not the .vue files that it imports. How can I fix this? My current workaround is to "manually" copy the files to .nuxt but of course I am looking for a better solution. Could it be that the plugin files need to be "stand-alone" meaning they are not allowed to import/require other dependencies?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
