Saturday, 20 April 2019

Compile template files/stubs into JS variables with Laravel mix

I have a folder /resources/js/stubs. In that folder sits a few files, lets say User.stub, Controller.stub and Migration.stub. I would like to use the content of these files in my javascript by doing something like this

import Templates from './Templates.js'
console.log(Templates.User)
// The content of User.stub is printed

I don't want to use this approach

module.exports = name => `
...
`

I could also use the backend to load the files into the view but I would prefer not to.

So then that requires preprocessing. Can I do it with Laravel mix somehow? If not what are my options, what do I need to add to my Laravel app?



from Compile template files/stubs into JS variables with Laravel mix

No comments:

Post a Comment