Erick Leopoldo
Erick Leopoldo

Reputation: 11

How to import a file from root project in nuxt-module?

I'm developing a nuxt-module, but I'm with a question:

How to import a file for example: file.config.js, that will be in the same folder position as nuxt.config.js.

The main idea is to import components on this file.config.js and be able to use it on as replacements from to the default components on my nuxt-module.

I want to do that because when I import vue components on my nuxt.config.js to send as properties to nuxt-module didn't works (error bellow):

Has someone a hint how to do that?

 FATAL  Unexpected token '<'                                                                                               16:27:12

  <template>
  ^
  
  SyntaxError: Unexpected token '<'
  at wrapSafe (internal/modules/cjs/loader.js:1001:16)
  at Module._compile (internal/modules/cjs/loader.js:1049:27)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
  at Module.load (internal/modules/cjs/loader.js:950:32)
  at Function.Module._load (internal/modules/cjs/loader.js:790:14)
  at Module.require (internal/modules/cjs/loader.js:974:19)
  at require (internal/modules/cjs/helpers.js:92:18)
  at g (node_modules/jiti/dist/jiti.js:1:54280)
  at src/pageeditor/modules/index.js:1:199
  at g (node_modules/jiti/dist/jiti.js:1:55111)

Upvotes: 1

Views: 1429

Answers (1)

Erick Leopoldo
Erick Leopoldo

Reputation: 11

I have found the answer for this problem.

It's not possible to import vue components on the build, so I use the addTemplate from the nuxt-modules.

https://nuxtjs.org/docs/internals-glossary/internals-module-container/#addtemplate-template

With that I could add the necessary files to the nuxt-module that I'm working on, and use this files on my vue-components.

Upvotes: 0

Related Questions