Comments (8)
Hey @ryanscherler I've just released v1.2.0 which adds the functionality you're after. Enjoy!
from laravel-mix-twig-to-html.
Awesome Ben! Thanks so much for updating to use globs! Stoked to try this out and integrate into our 'starter' setup
from laravel-mix-twig-to-html.
Hey Ryan, I'm glad you're enjoying it.
Globbing the paths is a good idea so I'll add support for it in the next release.
In the meantime, my other package get-files-in will help grab those twig/html files. If you have any files you don't want included you just need to prefix the folder with an underscore (eg: _pages).
For your example you'd use it like this:
const templateFiles = getFilesIn('src/templates/pages', ['twig', 'html'], true)
mix.twigToHtml({
files: templateFiles,
fileBase: 'src/templates/pages',
twigOptions: { data: {} },
enabled: true,
})
from laravel-mix-twig-to-html.
ps: the code snippit you provided just needs a small update to use a comma instead of pipe for the filetype matching:
files: ['src/templates/pages/**/*.{twig,html}'],
from laravel-mix-twig-to-html.
Quick question - the plugin also seems to inject the CSS / JS into the page? - is it possible to suppress this? e.g. we use Stimulus / Turbolinks and they need to be loaded into the head rather than prepended to the body.
from laravel-mix-twig-to-html.
That all seems possible and looks like it's a two-step process.
First step: Disable injections.
You can do this by setting your file config like this:
const mix = require('laravel-mix');
require('laravel-mix-twig-to-html');
const files = [
{
template: 'src/templates/pages/**/*.{twig,html}',
inject: false, // disable asset tag injection
}
]
mix.twigToHtml({
files: files,
fileBase: 'src/templates',
});
Then you need to specify the headTag and bodyTag positions in your twig base template(s) and add a filter where necessary:
<%= htmlWebpackPlugin
.tags
.headTags
.filter((tag) => tag.tagName === 'meta')
.join('')
%>
The injections should be fully customisable - take a look at this example
Alternatively, instead of inject: false
you could try setting inject: 'head'
or inject: 'body'
.
Hope that helps!
from laravel-mix-twig-to-html.
Oh thats great! I'll close my PR which addressed this with a fileOptions
config param.
from laravel-mix-twig-to-html.
thanks Ryan!
from laravel-mix-twig-to-html.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-mix-twig-to-html.