Reputation: 129
I have a .jade
source files and want to insert it into Vue app.
In sources I have the following code:
_mixins.jade:
- var domain = "example.com"
index.jade:
include _mixins
title #{domain}
And it, obviously, works.
What I want - is:
App.vue:
- var domain = "example.com"
div#app
HelloWorld
HelloWorld.vue:
h1 #{domain}
Is it possible at all? Or I'd have to have separate file with mixins and include it to every component, that'd use mixins and global variables?
Upvotes: 1
Views: 555
Reputation: 129
Based on @takeshi-tokugawa-yd's answer.
To add a global variable, you need to add a property to the global
object. As soon as you have this field in global
, pug will automatically resolve it without the need to touch its configuration.
Here is an example:
vite.config.ts
(global as any).domain = 'example.com';
(global as any).protocol = 'https';
index.pug
h1 #{protocol}://#{domain}
Hovewer, it is far from implicitly included mixin with variables as in the question. It's more an ugly hack, because you need to modify the global
object. Thus, I think that it's not possible to achieve what I wanted in the question.
Upvotes: 0
Reputation: 979
Yes. The specific method is dependent on your project building system.
pugPlugin(options, locals)
of vite-plugin-pug.globals
option.globals
option.Upvotes: 1